I just started using Golang 2 days ago, so this is probably pretty simple, but nevertheless hard for me.
The first step of my question was to serve multiple files under the directory "/static", which I already know how to do (
func main() {
fs := http.FileServer(http.Dir("./static"))
http.Handle("/", fs)
log.Println("Listening on :3000...")
err := http.ListenAndServe(":3000", nil)
if err != nil {
log.Fatal(err)
}
})
), but I want to make POST requests too (to save information to a MongoDB database) which is the part that stumps me. There is a code sample that does allow to serve one static file and a POST request, but I couldn't modify with my abilities. This sample can be found here:https://www.golangprograms.com/example-to-handle-get-and-post-request-in-golang.html. Can I make it somehow to serve multiple static files (under the directory "static" preferably)?