Gin + EdgeOne Pages

Build high-performance web applications with Gin framework. Features routing groups, middleware, JSON binding, and dynamic parameters.

cloud-functions/api.go
package main

import (
    "github.com/gin-gonic/gin"
    "net/http"
)

func main() {
    r := gin.Default()

    // REST API v1 group
    v1 := r.Group("/v1")
    {
        v1.GET("/hello", helloHandler)
        v1.GET("/health", healthHandler)

        // Users group
        users := v1.Group("/users")
        {
            users.GET("", listUsersHandler)
            users.GET("/:id", getUserHandler)
            users.POST("", createUserHandler)
        }
    }

    r.Run(":9000")
}

API Endpoints

GET/api/v1/hello

Simple GET route returning a welcome message

GET/api/v1/health

Health check endpoint with Go runtime info

GET/api/v1/users

GET route with JSON array response

GET/api/v1/users/42

Dynamic route parameter with c.Param("id")

POST/api/v1/users

POST route with JSON request body binding

Request Body:

{
  "name": "Alice",
  "email": "alice@example.com"
}
GET/api/v1/posts

Another resource group demonstrating route organization

GET/api/v1/posts/7

Dynamic param in posts group

Routing Groups

Organize APIs with nested route groups and middleware

JSON Binding

Automatic request body parsing with struct validation

Middleware Support

Custom middleware for logging, auth, and more