forked from danielvladco/go-proto-gql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.go
53 lines (48 loc) · 1.03 KB
/
schema.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
package plugin
import (
"bytes"
"fmt"
"github.com/gogo/protobuf/protoc-gen-gogo/generator"
)
type schema struct {
indent string
buffer *bytes.Buffer
*generator.Generator
}
// In Indents the output one tab stop.
func (s *schema) In() { s.indent += "\t" }
// Out unindents the output one tab stop.
func (s *schema) Out() {
if len(s.indent) > 0 {
s.indent = s.indent[1:]
}
}
func (s *schema) P(str ...interface{}) {
g := s.buffer
_, _ = fmt.Fprint(g, s.indent)
for _, v := range str {
switch s := v.(type) {
case string:
_, _ = fmt.Fprint(g, s)
case *string:
_, _ = fmt.Fprint(g, *s)
case bool:
_, _ = fmt.Fprintf(g, "%t", s)
case *bool:
_, _ = fmt.Fprintf(g, "%t", *s)
case int:
_, _ = fmt.Fprintf(g, "%d", s)
case *int32:
_, _ = fmt.Fprintf(g, "%d", *s)
case *int64:
_, _ = fmt.Fprintf(g, "%d", *s)
case float64:
_, _ = fmt.Fprintf(g, "%g", s)
case *float64:
_, _ = fmt.Fprintf(g, "%g", *s)
default:
panic(fmt.Sprintf("unknown type in printer: %T", v))
}
}
g.WriteByte('\n')
}