lundi 30 décembre 2019

Golang http.handlefunc always match "/"

Code:

http.HandleFunc("/", api.Index)
http.HandleFunc("/list", api.FileList)

http.HandleFunc("/api/upload", api.UploadFile)
http.HandleFunc("/api/delete", api.DeleteFile)

http.Handle("/files", http.StripPrefix("/files/", http.FileServer(http.Dir(settings.FilesPath))))

http.ListenAndServe(":1234", nil)

Result 1:

http://localhost:1234/

http://localhost:1234/list

http://localhost:1234/files

match "/"

api.index (it's wrong for the second and third)

Result 2:

http://localhost:1234/api/upload

http://localhost:1234/api/delete

match "/api/xxx"

api.xxx (it's right)

env:

go 1.13.5 windows/amd64

What should I do to fix this problem?

Thanks very much




Aucun commentaire:

Enregistrer un commentaire