-
Notifications
You must be signed in to change notification settings - Fork 1
/
placeholder.go
131 lines (102 loc) · 2.25 KB
/
placeholder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package main
import (
"fmt"
"strings"
)
func makeProtoPlaceholder(service string) []byte {
content := fmt.Sprintf(`
syntax = "proto3";
package %s.v1;
import "google/api/annotations.proto";
// TODO: Edit this proto to something more meaningful for your application.
service Service {
rpc GetVersion(GetVersionRequest) returns (GetVersionResponse) {
option (google.api.http) = {
post: "/v1/hello"
body: "*"
};
}
}
message GetVersionRequest {
string name = 1;
}
message GetVersionResponse {
string message = 1;
}
`, service)
return []byte(strings.Trim(content, "\n"))
}
func makeMainPlaceholder(module string) []byte {
content := fmt.Sprintf(`
package main
import (
"os"
"os/signal"
"syscall"
log "github.com/sirupsen/logrus"
service_interface "%s/internal/interface"
)
//nolint:all
var (
version = "dev"
commit = "none"
date = "unknown"
)
// TODO: Edit this file to something more meaningful for your application.
func main() {
svc, err := service_interface.NewService()
if err != nil {
log.Fatal(err)
}
log.RegisterExitHandler(svc.Stop)
log.Info("starting service...")
if err := svc.Start(); err != nil {
log.Fatal(err)
}
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
<-sigChan
log.Info("shutting down service...")
log.Exit(0)
}
`, module)
return []byte(strings.Trim(content, "\n"))
}
func makeInterfacePlaceholder(module string) []byte {
content := fmt.Sprintf(`
package service_interface
import (
grpc_interface "%s/internal/interface/grpc"
)
// TODO: Edit this file to something more meaningful for your application.
type Service interface {
Start() error
Stop()
}
func NewService() (Service, error) {
return grpc_interface.NewService()
}
`, module)
return []byte(strings.Trim(content, "\n"))
}
func makeServicePlaceholder() []byte {
content := `
package grpc_interface
import (
log "github.com/sirupsen/logrus"
)
// TODO: Edit this file to something more meaningful for your application.
type service struct {}
func NewService() (*service, error) {
return &service{}, nil
}
func (s *service) Start() error {
log.Debug("service is listening")
return nil
}
func (s *service) Stop() {
log.Debug("service stopped")
}
`
return []byte(strings.Trim(content, "\n"))
}