/
utils.go
63 lines (53 loc) · 1.2 KB
/
utils.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
package codegen
import (
"bytes"
"fmt"
"strings"
"encr.dev/cli/internal/version"
meta "encr.dev/proto/encore/parser/meta/v1"
)
func doNotEditHeader() string {
return fmt.Sprintf("Code generated by the Encore %s client generator. DO NOT EDIT.", version.Version)
}
func hasPublicRPC(svc *meta.Service) bool {
for _, rpc := range svc.Rpcs {
if rpc.AccessType != meta.RPC_PRIVATE {
return true
}
}
return false
}
type indentWriter struct {
w *bytes.Buffer
depth int
indent string
firstWriteOnLine bool
}
func (w *indentWriter) Indent() *indentWriter {
return &indentWriter{
w: w.w,
depth: w.depth + 1,
indent: w.indent,
firstWriteOnLine: true,
}
}
func (w *indentWriter) WriteString(s string) {
parts := strings.Split(s, "\n")
for i, part := range parts {
if i > 0 {
w.w.WriteString("\n")
w.firstWriteOnLine = true
}
if part == "" {
continue
}
if w.firstWriteOnLine {
w.w.WriteString(strings.Repeat(w.indent, w.depth))
w.firstWriteOnLine = false
}
w.w.WriteString(part)
}
}
func (w *indentWriter) WriteStringf(s string, args ...interface{}) {
w.WriteString(fmt.Sprintf(s, args...))
}