Skip to main content

Initializing Go 1.x Gin-Gonic App

Creating new Go 1.x Gin-Gonic Application

User will be able to initialize Go 1.x Gin-Gonic Application using the following command:

lc code init --name "<AppName>" --module "<ModuleName>" --function "<FunctionName>" --language "go1.x" --web "gin"

File Structure

The user will then be presented with a few files, similar to native go entry function:

│ .env << Environment Variable
│ .lyrid-definition.yml << Module Definition
│ go.mod
│ main.go << Main

entry.go << Entry Function

Using Existing Go 1.x Gin-Gonic Application

You can easily convert your existing Gin-Gonic to serverless, just in 3 steps !

1. COPY existing Gin-Gonic Application

Rename your main.go to rawentry.go , then copy the whole directory of your existing Gin Application to the \<AppName\>.\<ModuleName\> directory.


Make sure you always save duplicate copy so you dont mess up.

2. EDIT and TEST

Now, append your existing main function rawentry.go to <FunctionName>/entry.go in the Initialize() Function


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

Copy to \<FunctionName>/entry.go

func Initialize() *gin.Engine {
router := gin.Default()
return router

In the entry file, rather than serving your router by using router.Run(), you need to return the router, so the main function will be able to run your application as serverless.

Now, try running main.go. It should work just like your existing native Gin Project.


Go back to your terminal , get into your working directory \<AppName\>.\<ModuleName\>, then call

lc code submit