You build a Go blog engine by initializing a module, creating an HTTP handler to serve posts, and running the server.
-
Initialize the module and create the main file.
go mod init blog && touch main.go -
Add the HTTP handler code to
main.goto serve a static "Hello" page. `cat > main.go << 'EOF' package main
import ( "fmt" "net/http" )
func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello, Blog!") }) http.ListenAndServe(":8080", nil) } EOF`
- Run the server to start your blog engine.
go run main.go