Hello World
First, let's create a new file named main.go
and add the following code:
package main
import "github.com/dinever/golf"
func mainHandler(ctx *golf.Context) {
ctx.Send("Hello World!")
}
func main() {
app := golf.New()
app.Get("/", mainHandler)
app.Run(":9000")
}
To run this program, use the following command:
$ go run main.go
Alternatively, you can also build this go source file into a binary executable program:
$ go build main.go
Run the compiled binary executable program directly:
$ ./main
This program listens to the port 9000 and returns "Hello World!" whenever a request comes to the root URL(/). For every other path, the program returns a 404 Not Found.
Updated less than a minute ago