|
| 1 | +--- |
| 2 | +title: "Getting Started with INFINI Framework - Our homemade framework for building enterprise golang applications" |
| 3 | +meta_title: "Getting Started with INFINI Framework - Our homemade framework for building enterprise golang applications" |
| 4 | +description: "Discover how Coco AI revolutionizes enterprise search and collaboration with unified data and Gen-AI chat capabilities." |
| 5 | +date: 2024-12-15T08:00:00Z |
| 6 | +image: "/images/posts/2024/introducing-infini-framework.jpg" |
| 7 | +categories: ["Framework", "Golang"] |
| 8 | +author: "Medcl" |
| 9 | +tags: ["INFINI Framework", "Golang", "Framework", "Enterprise"] |
| 10 | +draft: false |
| 11 | +--- |
| 12 | + |
| 13 | +We recently open-sourced our homemade framework for building enterprise golang applications, called INFINI Framework. |
| 14 | + |
| 15 | +The github repo is [https://github.com/infinilabs/framework](https://github.com/infinilabs/framework). |
| 16 | + |
| 17 | +In this article, I will show you how to get started with INFINI Framework. |
| 18 | + |
| 19 | +# Create New Application |
| 20 | + |
| 21 | +Let's use the `NewAPP` as the new project for example. |
| 22 | + |
| 23 | +## Create the project folder |
| 24 | + |
| 25 | +Use the name `new_app` as the project id, and create the project folder as below: |
| 26 | +```shell |
| 27 | +cd ~/go/src/infini.sh/ |
| 28 | +mkdir new_app |
| 29 | +``` |
| 30 | +> Note: Ensure that `new_app` is located in the same directory as the `framework` folder. This structure is required for the Makefile to function correctly. |
| 31 | +
|
| 32 | +## Create the main file |
| 33 | + |
| 34 | +Create a empty `main.go` file, and paste the code as below: |
| 35 | + |
| 36 | +```shell |
| 37 | +package main |
| 38 | + |
| 39 | +import ( |
| 40 | + "infini.sh/framework" |
| 41 | + "infini.sh/framework/core/module" |
| 42 | + "infini.sh/framework/core/util" |
| 43 | + "infini.sh/framework/modules/api" |
| 44 | + "infini.sh/new_app/config" |
| 45 | +) |
| 46 | + |
| 47 | +func main() { |
| 48 | + |
| 49 | + terminalHeader := (" __ _ ___ ___ \n") |
| 50 | + terminalHeader += (" /\\ \\ \\_____ __/_\\ / _ \\/ _ \\\n") |
| 51 | + terminalHeader += (" / \\/ / _ \\ \\ /\\ / //_\\\\ / /_)/ /_)/\n") |
| 52 | + terminalHeader += ("/ /\\ / __/\\ V V / _ \\/ ___/ ___/ \n") |
| 53 | + terminalHeader += ("\\_\\ \\/ \\___| \\_/\\_/\\_/ \\_/\\/ \\/ \n\n") |
| 54 | + |
| 55 | + terminalFooter := ("Goodbye~") |
| 56 | + app := framework.NewApp("new_app", "Make a golang application is such easy~.", |
| 57 | + util.TrimSpaces(config.Version), util.TrimSpaces(config.BuildNumber), util.TrimSpaces(config.LastCommitLog), util.TrimSpaces(config.BuildDate), util.TrimSpaces(config.EOLDate), terminalHeader, terminalFooter) |
| 58 | + app.IgnoreMainConfigMissing() |
| 59 | + app.Init(nil) |
| 60 | + defer app.Shutdown() |
| 61 | + if app.Setup(func() { |
| 62 | + module.RegisterSystemModule(&api.APIModule{}) |
| 63 | + module.Start() |
| 64 | + }, func() { |
| 65 | + }, nil) { |
| 66 | + app.Run() |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | +
|
| 71 | +> You may use this online tool to generate your beauty ASCII based terminal header: [http://patorjk.com/software/taag/#p=display&h=2&v=1&f=Ogre&t=NewAPP](http://patorjk.com/software/taag/#p=display&h=2&v=1&f=Ogre&t=NewAPP) |
| 72 | +
|
| 73 | +## Create the config file |
| 74 | +```shell |
| 75 | +touch new_app.yml |
| 76 | +``` |
| 77 | +## Create the makefile |
| 78 | +
|
| 79 | +create a empty `Makefile`, and paste the code as below: |
| 80 | +
|
| 81 | +```shell |
| 82 | +SHELL=/bin/bash |
| 83 | +
|
| 84 | +# APP info |
| 85 | +APP_NAME := new_app |
| 86 | +APP_VERSION := 1.0.0_SNAPSHOT |
| 87 | +APP_CONFIG := $(APP_NAME).yml |
| 88 | +APP_EOLDate ?= "2025-12-31T10:10:10Z" |
| 89 | +APP_STATIC_FOLDER := .public |
| 90 | +APP_STATIC_PACKAGE := public |
| 91 | +APP_UI_FOLDER := ui |
| 92 | +APP_PLUGIN_FOLDER := plugins |
| 93 | +PREFER_MANAGED_VENDOR=fase |
| 94 | +
|
| 95 | +include ../framework/Makefile |
| 96 | +``` |
| 97 | +
|
| 98 | +## Build the application |
| 99 | +```shell |
| 100 | +➜ new_app OFFLINE_BUILD=true make build |
| 101 | +building new_app 1.0.0_SNAPSHOT main |
| 102 | +/Users/medcl/go/src/infini.sh/new_app |
| 103 | +framework path: /Users/medcl/go/src/infini.sh/framework |
| 104 | +fatal: not a git repository (or any of the parent directories): .git |
| 105 | +update generated info |
| 106 | +update configs |
| 107 | +(cd ../framework/ && make update-plugins) || true # build plugins in framework |
| 108 | +GOPATH=~/go:~/go/src/infini.sh/framework/../vendor/ CGO_ENABLED=0 GRPC_GO_REQUIRE_HANDSHAKE=off GO15VENDOREXPERIMENT="1" GO111MODULE=off go build -a -gcflags=all="-l -B" -ldflags '-static' -ldflags='-s -w' -gcflags "-m" --work -o /Users/medcl/go/src/infini.sh/new_app/bin/new_app |
| 109 | +WORK=/var/folders/j5/qd4qt3n55dz053d93q2mswfr0000gn/T/go-build435280758 |
| 110 | +# infini.sh/new_app |
| 111 | +./main.go:17:9: can inline main.deferwrap1 |
| 112 | +./main.go:21:12: can inline main.func2 |
| 113 | +./main.go:18:22: func literal does not escape |
| 114 | +./main.go:19:45: &api.APIModule{} escapes to heap |
| 115 | +./main.go:21:12: func literal escapes to heap |
| 116 | +restore generated info |
| 117 | +``` |
| 118 | +
|
| 119 | +## Run the application |
| 120 | +```shell |
| 121 | +➜ new_app git:(main) ✗ ./bin/new_app |
| 122 | + __ _ ___ ___ |
| 123 | + /\ \ \_____ __/_\ / _ \/ _ \ |
| 124 | + / \/ / _ \ \ /\ / //_\\ / /_)/ /_)/ |
| 125 | +/ /\ / __/\ V V / _ \/ ___/ ___/ |
| 126 | +\_\ \/ \___| \_/\_/\_/ \_/\/ \/ |
| 127 | +
|
| 128 | +[NEW_APP] Make a golang application is such easy~. |
| 129 | +[NEW_APP] 1.0.0_SNAPSHOT#001, 2024-12-16 06:15:10, 2025-12-31 10:10:10, HEAD |
| 130 | +[12-16 14:15:19] [INF] [env.go:203] configuration auto reload enabled |
| 131 | +[12-16 14:15:19] [INF] [env.go:209] watching config: /Users/medcl/go/src/infini.sh/new_app/config |
| 132 | +[12-16 14:15:19] [INF] [app.go:311] initializing new_app, pid: 64426 |
| 133 | +[12-16 14:15:19] [INF] [app.go:312] using config: /Users/medcl/go/src/infini.sh/new_app/new_app.yml |
| 134 | +[12-16 14:15:19] [INF] [api.go:214] local ips: 192.168.3.17 |
| 135 | +[12-16 14:15:19] [INF] [api.go:312] api server listen at: http://0.0.0.0:2900 |
| 136 | +[12-16 14:15:19] [INF] [module.go:159] started module: api |
| 137 | +[12-16 14:15:19] [INF] [module.go:184] all modules are started |
| 138 | +[12-16 14:15:19] [INF] [instance.go:101] workspace: /Users/medcl/go/src/infini.sh/new_app/data/new_app/nodes/ctfs8hbq50kevmkb3m6g |
| 139 | +[12-16 14:15:19] [INF] [app.go:537] new_app is up and running now. |
| 140 | +^C |
| 141 | +[NEW_APP] got signal: interrupt, start shutting down |
| 142 | +[12-16 14:15:23] [INF] [module.go:213] all modules are stopped |
| 143 | +[12-16 14:15:23] [INF] [app.go:410] new_app now terminated. |
| 144 | +[NEW_APP] 1.0.0_SNAPSHOT, uptime: 4.13334s |
| 145 | +
|
| 146 | +Goodbye~ |
| 147 | +``` |
| 148 | +
|
| 149 | +## Conclusion |
| 150 | +
|
| 151 | +By leveraging the INFINI Framework, creating a Go application becomes significantly simpler and more efficient. |
| 152 | +The framework provides built-in commands and modules, streamlining the development process and enabling you to focus on building your application's core functionality. |
0 commit comments