Kite is a golang project structure's code generation that build the base project and provide tools to help for creating a new projects
Clone this repo
git clone https://github.com/nurcahyaari/kite.git
then open the directory in your terminal app.
go build kite.go
The app was built as binary. then move the binary app into your $PATH environment
This following bash script is the example to generate project using Kite
Command | Function |
---|---|
kite new --name | Create new application/ project/ service |
main module --name | creating new modules such as, product modules, user modules, auth modules, etc |
after you have done to setup your binary of kite in your environtment $PATH you can use kite to create your new applications
command
kite new --args1 value --args2 value
args | function |
---|---|
name | your application name |
path | your application path |
example, I created new Backend service for my apps called as Todo-Backend
. and I want to save this service at my Documents package /usr/Documents
- First I can use command
cd
to go to/usr/Documents
- Or I can use the path args in kite generation command
kite new --name Todo-Backend --path /usr/Documents
After I've created my Backend I must create my Modules first
because when you create your new apps, currently the generator will not create your first module. you must to create your modules to determines that your service working
command
kite module --args1 value --args2 value
args | function |
---|---|
name | your module name |
path | your application path |
The module name is Test
and it is under of my Todo-Backend
so I will use this command
kite module --name Test --path --value /usr/Documents/Todo-Backend
because, Kite still doesn't support to auto adding modules into wire.go. after adding the new modules you must manually inject your modules and any others dependencies into wire.go manually.
after you create your new project, and your new module then you must:
- add your handlers into internal/protocols/http/router/route.go
- add package src/handlers/http into protocols/http/http.go, it should be look like this
package router
import (
"github.com/go-chi/chi/v5"
"Todo-Backend/src/handlers/http"
)
type HttpRouterImpl struct {
httpHandlers http.HttpHandler
}
func NewHttpRouter(httpHandlers http.HttpHandler) *HttpRouterImpl {
return &HttpRouterImpl{
httpHandlers: httpHandlers,
}
}
func (h *HttpRouterImpl) Router(r *chi.Mux) {
h.httpHandlers.Router(r)
}
- add your new modules into wire.go
first you must add into your import package
add your test module's repo testrepo "Todo-Backend/src/modules/test/repository"
add your test module's service testsvc "Todo-Backend/src/modules/test/service"
var testRepo = wire.NewSet(
testrepo.NewTestRepository,
wire.Bind(
new(testrepo.TestRepository),
new(*testrepo.TestRepositoryImpl),
),
)
var testSvc = wire.NewSet(
testsvc.NewTestService,
wire.Bind(
new(testsvc.TestService),
new(*testsvc.TestServiceImpl),
),
)
and add into domain variables in wire.go
var domain = wire.NewSet(
testSvc,
)
- run
go generate ./...
- copy your .env.example into .env
- if you've got an error, install the package that needed in your project
- run your project with this command
go run main.go wire_gen.go