Answers for "how to serve static files in golang"

CSS
1

how to serve css in golang

// if you keep all css and js in a static folder
// you can use this

func main() {
  http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
}
Posted by: Guest on October-26-2020
0

go static server

package main

import (
  "log"
  "net/http"
)

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)
  }
}
Posted by: Guest on September-27-2020

Code answers related to "how to serve static files in golang"

Browse Popular Code Answers by Language