💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
**注册 Request Handler** ~~~go func (w http.ResponseWriter, r *http.Request) ~~~ 这个函数接收两个参数: http.ResponseWriter:text/html响应 http.Request:包含关于这个HTTP请求的所有信息,包括像URL或header simple demo ~~~go http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, you've requested: %s\n", r.URL.Path) }) ~~~ 一个request handler 无法接受外部HTTP的请求,需要一个监听某个端口的http server来处理request,将其传给对应的request handler。 ~~~go http.ListenAndServe(":80", nil) ~~~ <details> <summary> Demo </summary> ``` package main import ( "fmt" "net/http" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, you've requested: %s\n", r.URL.Path) }) http.ListenAndServe(":80", nil) } ``` </details> ***** **http.FileServer** ``` fs := http.FileServer(http.Dir("static/")) http.Handle("/static/", http.StripPrefix("/static/", fs)) ```