我是Go的新手.从文档中尝试了第一个hello,world,并希望从请求中读取Host和Scheme:
package hello
import (
"fmt"
"http"
)
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Host: " + r.URL.Host + " Scheme: " + r.URL.Scheme)
}
Run Code Online (Sandbox Code Playgroud)
但他们的价值观都是空白的.为什么?
假设我有以下观点,
from fastapi import FastAPI
app = FastAPI()
@app.get('/hello/')
def hello_world():
return {"msg": "Hello World"}
@app.get('/hello/{number}/')
def hello_world_number(number: int):
return {"msg": "Hello World Number", "number": number}
Run Code Online (Sandbox Code Playgroud)
我一直在 Flask 和 Django 中使用这些函数
所以,我怎样才能获得/建立的网址,hello_world并hello_world_number以类似的方式?