Chapter 2: Installation Deep Dive for Go

In this chapter, we will go deep into the installation process. By the end, you will have a fully configured development environment with hot reload, debugging, and all the tools you need.

System Requirements

Kungfu.js has two components:

  • The Rust core: Handles HTTP, routing, middleware. Needs Rust 1.96+ installed.
  • The Go binding: Lets you write handlers in Go. Needs the Go runtime.

You need Go 1.21+.

Step 1: Install Rust

Rust is required because it compiles the HTTP server engine. Even if you write in Go, the server itself runs Rust code.

# On macOS or Linux:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# On Windows:
# Download rustup-init.exe from https://rustup.rs

Verify Rust is installed:

rustc --version
# Should print: rustc 1.96+

Step 2: Install the Go Binding

Now install the Kungfu.js package for Go:

go get github.com/Resolutefemi/kungfu/bindings/go

Step 3: Verify the Installation

Create a test file and run it to make sure everything works:

package main
import "github.com/Resolutefemi/kungfu/bindings/go/kungfu"

func main() {
    app := kungfu.New()
    app.Get("/hello", func(w kungfu.ResponseWriter, r *kungfu.Request) {
        w.Text(200, "world")
    })
    app.Run(":3000")
}

Run it:

go run main.go

If you see "world" at http://localhost:3000/hello, your installation is complete.

Common Installation Problems

Problem: "command not found: rustc"

Rust is not in your PATH. Run source $HOME/.cargo/env or restart your terminal.

Problem: "port 3000 already in use"

Another application is using port 3000. Either stop that app or use a different port: .listen(3001)

Problem: Build fails with "linker not found"

You need a C linker installed. On Ubuntu: sudo apt install build-essential. On macOS: xcode-select --install.

Development Environment Setup

For the best development experience, install the Kungfu.js VSCode extension. It provides:

  • Syntax highlighting for .jsk and .tsk files
  • Code snippets (type kget and press Tab)
  • The green hexagon icon for Kungfu.js files

What is Next?

In chapter 3, we will dissect the Hello World code line by line, explaining every function, every parameter, and why things work the way they do.