A function request demonstration website based on Next.js + Tailwind CSS, showcasing how to deploy Go Cloud Functions using Handler Mode on EdgeOne Pages with file-based routing.
- File-Based Routing: Go handler files map directly to API endpoints, just like Next.js file routing
- Modern UI Design: Adopts black background with white text theme, using #1c66e5 as accent color
- Real-time API Demo: Integrated Go backend with interactive API call testing for all route types
- Multiple Route Patterns: Supports static, index, dynamic, nested dynamic, and catch-all routes
- TypeScript Support: Complete type definitions and type safety
- Next.js 15 - React full-stack framework
- React 19 - User interface library
- TypeScript - Type-safe JavaScript
- Tailwind CSS 4 - Utility-first CSS framework
- 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
- Go 1.21 - Cloud Functions runtime
- Handler Mode - File-based routing for Go functions on EdgeOne Pages
go-handler-template/
βββ cloud-functions/ # Go Cloud Functions source
β βββ hello.go # Static route β GET /hello
β βββ api/
β βββ posts/
β β βββ index.go # Index route β GET /api/posts
β βββ users/
β β βββ [userId].go # Dynamic param β GET /api/users/:userId
β β βββ [userId]/
β β βββ posts/
β β βββ [postId].go # Nested params β GET /api/users/:userId/posts/:postId
β βββ files/
β βββ [[path]].go # Catch-all β GET /api/files/*path
βββ src/
β βββ app/ # Next.js App Router
β β βββ globals.css # Global styles
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Main page (API demo UI)
β βββ components/ # React components
β β βββ ui/ # UI base components
β β βββ button.tsx # Button component
β β βββ card.tsx # Card component
β βββ lib/ # Utility functions
β βββ utils.ts # Common utilities
βββ public/ # Static assets
βββ package.json # Project configuration
βββ README.md # Project documentation
- Node.js 18+
- npm or yarn
- Go 1.21+ (for local development)
npm install
# or
yarn installedgeone pages devVisit http://localhost:8088 to view the application.
edgeone pages buildThe cloud-functions/ directory maps directly to API routes:
| File | Route | Pattern |
|---|---|---|
hello.go |
GET /hello |
Static route |
api/posts/index.go |
GET /api/posts |
Index route |
api/users/[userId].go |
GET /api/users/:userId |
Dynamic parameter |
api/users/[userId]/posts/[postId].go |
GET /api/users/:userId/posts/:postId |
Nested dynamic parameters |
api/files/[[path]].go |
GET /api/files/*path |
Catch-all route |
- Click "Call" to test each API endpoint in real-time
- View JSON response with syntax highlighting
- Expandable source file path display
Each Go file exports a standard Handler function:
package handler
import (
"encoding/json"
"net/http"
)
func Handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]interface{}{
"message": "Hello from Go Cloud Functions!",
})
}The project uses Tailwind CSS 4 with custom color variables:
:root {
--primary: #1c66e5; /* Primary color */
--background: #000000; /* Background color */
--foreground: #ffffff; /* Foreground color */
}Uses class-variance-authority to manage component style variants with multiple preset styles.
- EdgeOne Pages Official Docs: https://pages.edgeone.ai/document/go-functions
- Next.js Documentation: https://nextjs.org/docs
- Tailwind CSS Documentation: https://tailwindcss.com/docs
- Go Documentation: https://go.dev/doc
- Push code to GitHub repository
- Create new project in EdgeOne Pages console
- Select GitHub repository as source
- Configure build command:
edgeone pages build - Deploy project
Create cloud-functions/ folder in project root and add Go handler files:
// cloud-functions/hello.go
package handler
import (
"encoding/json"
"net/http"
)
func Handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{
"message": "Hello from Go!",
})
}This project is licensed under the MIT License - see the LICENSE file for details.