Back to Templates

Go Gin - Cloud Functions on EdgeOne Pages

Use Gin on EdgeOne Pages with middleware, JSON binding, route groups, and RESTful API design.

View Demo
FrameworkGo
Use CaseStarter,Cloud Functions
Use Gin on EdgeOne Pages with middleware, JSON binding, route groups, and RESTful API design.

Go Cloud Functions on EdgeOne Pages - Gin Framework

A full-stack demo application built with Next.js + Tailwind CSS frontend and Go Gin backend, showcasing how to deploy Go Cloud Functions using the Gin framework on EdgeOne Pages with RESTful API routing.

๐Ÿš€ Features

  • Gin Framework Integration: Full-featured Go web framework with middleware, JSON binding, and route groups
  • Modern UI Design: Dark theme with #1c66e5 accent color, responsive layout with interactive elements
  • Interactive API Testing: Built-in API endpoint panel โ€” click "Call" to test each REST endpoint in real-time
  • RESTful API Design: Complete CRUD operations with structured route groups (/v1/users, /v1/posts)
  • TypeScript Support: Complete type definitions and type safety on the frontend

๐Ÿ› ๏ธ Tech Stack

Frontend

  • Next.js 15 - React full-stack framework (with Turbopack)
  • React 19 - User interface library
  • TypeScript - Type-safe JavaScript
  • Tailwind CSS 4 - Utility-first CSS framework

UI Components

  • shadcn/ui - High-quality React components
  • Lucide React - Beautiful icon library
  • class-variance-authority - Component style variant management
  • clsx & tailwind-merge - CSS class name merging utilities

Backend

  • Go 1.21 - Cloud Functions runtime
  • Gin v1.10 - High-performance HTTP web framework for Go

๐Ÿ“ Project Structure

go-gin-template/
โ”œโ”€โ”€ cloud-functions/                # Go Cloud Functions source
โ”‚   โ”œโ”€โ”€ api.go                     # Gin app with all REST API routes
โ”‚   โ”œโ”€โ”€ go.mod                     # Go module definition
โ”‚   โ””โ”€โ”€ go.sum                     # Go dependency checksums
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ app/                       # Next.js App Router
โ”‚   โ”‚   โ”œโ”€โ”€ globals.css           # Global styles (dark theme)
โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx            # Root layout
โ”‚   โ”‚   โ””โ”€โ”€ page.tsx              # Main page (API testing UI)
โ”‚   โ”œโ”€โ”€ components/               # React components
โ”‚   โ”‚   โ””โ”€โ”€ ui/                   # UI base components
โ”‚   โ”‚       โ”œโ”€โ”€ button.tsx        # Button component
โ”‚   โ”‚       โ””โ”€โ”€ card.tsx          # Card component
โ”‚   โ””โ”€โ”€ lib/                      # Utility functions
โ”‚       โ””โ”€โ”€ utils.ts              # Common utilities (cn helper)
โ”œโ”€โ”€ public/                        # Static assets
โ”‚   โ”œโ”€โ”€ eo-logo-blue.svg          # EdgeOne logo (blue)
โ”‚   โ””โ”€โ”€ eo-logo-white.svg         # EdgeOne logo (white)
โ”œโ”€โ”€ package.json                   # Project configuration
โ””โ”€โ”€ README.md                     # Project documentation

๐Ÿš€ Quick Start

Requirements

  • Node.js 18+
  • pnpm (recommended) or npm
  • Go 1.21+ (for local development)

Install Dependencies

pnpm install
# or
npm install

Development Mode

edgeone pages dev

Visit http://localhost:8088 to view the application.

Build Production Version

edgeone pages build

๐ŸŽฏ Core Features

1. Gin REST API Routes

All API endpoints are defined in a single cloud-functions/api.go file using Gin's route groups:

MethodRouteDescription
GET/api/v1/helloWelcome message
GET/api/v1/healthHealth check (includes Go runtime version)
GET/api/v1/usersList all users
GET/api/v1/users/:idGet user by ID
POST/api/v1/usersCreate new user (JSON body binding)
GET/api/v1/postsList all posts
GET/api/v1/posts/:idGet post by ID

2. Interactive API Testing Panel

  • 7 pre-configured API endpoint cards with "Call" buttons
  • Real-time JSON response display with syntax highlighting
  • POST request support with pre-filled JSON body
  • Loading states and error handling

3. Gin Framework Convention

The Go backend uses Gin's standard patterns โ€” route groups, JSON binding, and middleware:

package main

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

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

    v1 := r.Group("/v1")
    {
        v1.GET("/hello", func(c *gin.Context) {
            c.JSON(http.StatusOK, gin.H{
                "message": "Hello from Go Gin!",
            })
        })

        v1.GET("/users", getUsersHandler)
        v1.GET("/users/:id", getUserByIdHandler)
        v1.POST("/users", createUserHandler)
    }

    r.Run(":9000")
}

4. Data Models

type User struct {
    ID    int    `json:"id"`
    Name  string `json:"name"`
    Email string `json:"email"`
}

type Post struct {
    ID    int    `json:"id"`
    Title string `json:"title"`
    Body  string `json:"body"`
}

๐Ÿ”ง Configuration

Tailwind CSS Configuration

The project uses Tailwind CSS 4 with custom color variables:

:root {
  --primary: #1c66e5;        /* Primary color */
  --background: #000000;     /* Background color */
  --foreground: #ffffff;     /* Foreground color */
}

Component Styling

Uses class-variance-authority to manage component style variants with multiple preset styles.

๐Ÿ“š Documentation

๐Ÿš€ Deployment Guide

EdgeOne Pages Deployment

  1. Push code to GitHub repository
  2. Create new project in EdgeOne Pages console
  3. Select GitHub repository as source
  4. Configure build command: edgeone pages build
  5. Deploy project

Go Gin Cloud Function

Create cloud-functions/api.go in project root with your Gin application:

package main

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

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

    r.GET("/v1/hello", func(c *gin.Context) {
        c.JSON(http.StatusOK, gin.H{
            "message": "Hello from Go Gin on EdgeOne Pages!",
        })
    })

    r.Run(":9000")
}

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.