mirror of
https://github.com/cubixle/tuugen.git
synced 2026-04-24 21:24:42 +01:00
wip
This commit is contained in:
7
templates/data_model.go.tmpl
Normal file
7
templates/data_model.go.tmpl
Normal file
@@ -0,0 +1,7 @@
|
||||
package storage
|
||||
|
||||
import "time"
|
||||
|
||||
type {{ .Name }} struct { {{ range .Properties }}
|
||||
{{ .NameCorrected }} {{ .DBTypeToGoType }}{{ end }}
|
||||
}
|
||||
15
templates/interactors.go.tmpl
Normal file
15
templates/interactors.go.tmpl
Normal file
@@ -0,0 +1,15 @@
|
||||
package interactors
|
||||
|
||||
import (
|
||||
"fmt"{{ range .Imports }}
|
||||
"{{ . }}"{{ end }}
|
||||
)
|
||||
|
||||
type Interactor struct {
|
||||
|
||||
}
|
||||
{{ range .Funcs }}
|
||||
func (i *Interactor) {{ .Name }}({{.ArgsToStr}}) {{ if gt (len .Returns) 0 }}({{.ListToStr .Returns}}){{end}} {
|
||||
return nil, fmt.Errorf("unimplemented")
|
||||
}
|
||||
{{ end }}
|
||||
33
templates/main.go.tmpl
Normal file
33
templates/main.go.tmpl
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"net"
|
||||
"log"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
pb "{{.ImportPath}}/{{.GRPCPath}}"
|
||||
"{{.ImportPath}}/internal/service"
|
||||
)
|
||||
|
||||
func main() {
|
||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%s", getEnv("GRPC_PORT", "8090")))
|
||||
if err != nil {
|
||||
log.Fatalf("failed to listen: %v", err)
|
||||
}
|
||||
|
||||
s := grpc.NewServer()
|
||||
pb.Register{{.ServiceName}}Server(s, service.New())
|
||||
if err := s.Serve(lis); err != nil {
|
||||
log.Fatalf("failed to serve: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(name, defaultValue string) string {
|
||||
v := os.Getenv(name)
|
||||
if v == "" {
|
||||
return defaultValue
|
||||
}
|
||||
return v
|
||||
}
|
||||
26
templates/service.go.tmpl
Normal file
26
templates/service.go.tmpl
Normal file
@@ -0,0 +1,26 @@
|
||||
package service
|
||||
|
||||
import ({{ range .Imports }}
|
||||
"{{ . }}"{{ end }}
|
||||
)
|
||||
|
||||
func New() *Service {
|
||||
return &Service{}
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
interactor *interactors.Interactor
|
||||
}
|
||||
{{ range .Funcs }}
|
||||
func (s *Service) {{ .Name }}({{.ArgsToStr}}) {{ if gt (len .Returns) 0 }}({{.ListToStr .Returns}}){{end}} {
|
||||
res, err := s.interactor.{{.Name}}(ctx, req)
|
||||
if err != nil {
|
||||
return nil, errorToGRPCError(err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
func errorToGRPCError(err error) error {
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user