我是 Go 的新手,我正在嘗試為 GAE 制作一些應用程序。我找不到和我有同樣問題的人,所以我想我會在這里問!基本上,我正在創建一個程序,它將從數組中獲取一個隨機 url 并重定向用戶。出現的問題是,在我嘗試使用的每臺計算機上,它都會發送不同的視頻,但它始終會向該人發送相同的視頻。如果有人對此有任何見解,將不勝感激! package randvid import ( "net/http" "math/rand" "time" ) func RandLink() string{ VideoList := []string{ ... } r := rand.New(rand.NewSource(time.Now().UTC().UnixNano())) vid := r.Intn(len(VideoList)) + 1; return VideoList[vid] } func redirectHandler(path string) func(http.ResponseWriter, *http.Request) { return func (w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, path, http.StatusMovedPermanently) } } func init() { http.HandleFunc("/", redirectHandler(RandLink())) }
在 GAE 中使用重定向
慕婉清6462132
2021-11-15 15:58:25