package main import ( "net/http" "github.com/fragmenta/router" ) func handleIndex(context router.Context) error { context.Writer().Write([]byte("Hello, world!")) return nil } func main() { r := router.New() r.Get("/", handleIndex) http.ListenAndServe(":3000", r) }
package main import ( "fmt" "github.com/fragmenta/router" "net/http" ) func handleUser(context router.Context) error { id, err := context.ParamInt("id") if err != nil { return fmt.Errorf("Invalid user ID") } context.Writer().Write([]byte(fmt.Sprintf("User ID: %d", id))) return nil } func main() { r := router.New() r.Get("/users/:id", handleUser) http.ListenAndServe(":3000", r) }In this example, we define a handler function to retrieve and display the user ID from a URL parameter. We use the `Context.ParamInt()` method to extract the integer value of the `id` parameter, and write the response to the client. Overall, the `github.com/fragmenta/router` package library is a useful tool for developers looking to build flexible and scalable web applications in Go.