Root Routing
package main
import (
"fmt"
"log"
"net/http"
)
func handlerIndex(w http.ResponseWriter, r *http.Request) {
data := "Welcome to Web Applications written by GO"
w.Write([]byte(data))
}
func handlerAuthor(w http.ResponseWriter, r *http.Request) {
data := "David Winalda"
w.Write([]byte(data))
}
func main() {
http.HandleFunc("/", handlerIndex)
http.HandleFunc("/author", handlerAuthor)
port := "localhost:3030"
log.Println("Server started at", port)
err := http.ListenAndServe(port, nil)
if err != nil {
fmt.Println(err.Error())
}
}

Last updated