Getting Started
Build your first application with these simple steps.
Prerequisites
Basic knowledge of Go programming
A text editor or IDE of your choice
Zinc requires Go 1.22+ due to the latest changes to the net/http
package. If you don't have Go
installed, download it before continuing. To read more about
these changes, see the Go 1.22 release notes.
Create a New Project
Create a new directory for your project
mkdir my-zinc-app
cd my-zinc-app
touch server.go
Initialize your Go module
go mod init my-zinc-app
You will need to tidy your dependencies after initializing your module with go mod tidy
.
Install the Zinc framework
go get github.com/0mjs/zinc
Create Your First API
package main
import "github.com/0mjs/zinc"
func main() {
// Create the Zinc application
app := zinc.New()
// A simple GET route handler that returns "Hello, World!"
app.Get("/", func(c *zinc.Context) error {
return c.String("Hello, World!")
})
// A route handler that takes a path parameter and returns "Hello {name}"
app.Get("/hello/:name", func(c *zinc.Context) error {
return c.String("Hello " + c.Param("name"))
})
// Start the server
app.Serve()
}
Run your server
go run server.go
Your server is now running at http://localhost:6530
Test Your API
Visit the root endpoint
Open http://localhost:6530 in your browser to see "Hello, World!"
Try the route with a parameter
Visit http://localhost:6530/hello/zinc to see "Hello, zinc!"
Now is an important time to note that Zinc normalizes Path Parameters to lowercase by default. If you want
to use a different case, you can set the CaseSensitive
startup option to true
.