@@ -34,15 +34,20 @@ func (p *Proto) Markdown(title, fpath string, lopts ...string) error {
34
34
buf .WriteString (svs .Description )
35
35
buf .WriteString ("\n \n " )
36
36
}
37
- hd1 := "| Method | Request Type | Response Type | Description |"
38
- hd2 := "| ------ | ------------ | ------------- | ----------- |"
39
- buf .WriteString (hd1 + "\n " )
40
- buf .WriteString (hd2 + "\n " )
41
37
42
- for _ , elem := range svs .Methods {
43
- line := fmt .Sprintf ("| %s | `%s` | `%s` | %s |" , elem .Name , elem .RequestType , elem .ResponseType , elem .Description )
44
- buf .WriteString (line + "\n " )
38
+ if len (svs .Methods ) > 0 {
39
+ hd1 := "| Method | Request Type | Response Type | Description |"
40
+ hd2 := "| ------ | ------------ | ------------- | ----------- |"
41
+ buf .WriteString (hd1 + "\n " )
42
+ buf .WriteString (hd2 + "\n " )
43
+ for _ , elem := range svs .Methods {
44
+ line := fmt .Sprintf ("| %s | `%s` | `%s` | %s |" , elem .Name , elem .RequestType , elem .ResponseType , elem .Description )
45
+ buf .WriteString (line + "\n " )
46
+ }
47
+ } else {
48
+ buf .WriteString ("Empty method.\n " )
45
49
}
50
+
46
51
buf .WriteString ("\n \n <br>\n \n " )
47
52
}
48
53
@@ -52,55 +57,61 @@ func (p *Proto) Markdown(title, fpath string, lopts ...string) error {
52
57
buf .WriteString (msg .Description )
53
58
buf .WriteString ("\n \n " )
54
59
}
55
- hd1 := "| Field | Description | Type |"
56
- hd2 := "| ----- | ----------- | ---- |"
57
- for _ , lopt := range lopts {
58
- hd1 += fmt .Sprintf (" %s |" , lopt )
59
- ds := strings .Repeat ("-" , len (lopt ))
60
- if len (ds ) < 3 {
61
- ds = "---"
62
- }
63
- hd2 += fmt .Sprintf (" %s |" , ds )
64
- }
65
- buf .WriteString (hd1 + "\n " )
66
- buf .WriteString (hd2 + "\n " )
67
- for _ , elem := range msg .Fields {
68
- ts := elem .ProtoType .String ()
69
- if elem .UserDefinedProtoType != "" {
70
- ts = elem .UserDefinedProtoType
71
- }
72
- if elem .Repeated {
73
- ts = "(slice of) " + ts
74
- }
75
- line := fmt .Sprintf ("| %s | %s | %s |" , elem .Name , elem .Description , ts )
60
+
61
+ if len (msg .Fields ) > 0 {
62
+ hd1 := "| Field | Description | Type |"
63
+ hd2 := "| ----- | ----------- | ---- |"
76
64
for _ , lopt := range lopts {
65
+ hd1 += fmt .Sprintf (" %s |" , lopt )
66
+ ds := strings .Repeat ("-" , len (lopt ))
67
+ if len (ds ) < 3 {
68
+ ds = "---"
69
+ }
70
+ hd2 += fmt .Sprintf (" %s |" , ds )
71
+ }
72
+ buf .WriteString (hd1 + "\n " )
73
+ buf .WriteString (hd2 + "\n " )
74
+ for _ , elem := range msg .Fields {
75
+ ts := elem .ProtoType .String ()
77
76
if elem .UserDefinedProtoType != "" {
78
- line += " |"
79
- continue
77
+ ts = elem .UserDefinedProtoType
80
78
}
81
- formatSt := " %s |"
82
79
if elem .Repeated {
83
- formatSt = " (slice of) %s |"
80
+ ts = "(slice of) " + ts
84
81
}
85
- switch lopt {
86
- case "C++" :
87
- line += fmt .Sprintf (formatSt , elem .ProtoType .Cpp ())
88
- case "Java" :
89
- line += fmt .Sprintf (formatSt , elem .ProtoType .Java ())
90
- case "Python" :
91
- line += fmt .Sprintf (formatSt , elem .ProtoType .Python ())
92
- case "Go" :
93
- line += fmt .Sprintf (formatSt , elem .ProtoType .Go ())
94
- case "Ruby" :
95
- line += fmt .Sprintf (formatSt , elem .ProtoType .Ruby ())
96
- case "C#" :
97
- line += fmt .Sprintf (formatSt , elem .ProtoType .Csharp ())
98
- default :
99
- return fmt .Errorf ("%q is unknown (must be C++, Java, Python, Go, Ruby, C#)" , lopt )
82
+ line := fmt .Sprintf ("| %s | %s | %s |" , elem .Name , elem .Description , ts )
83
+ for _ , lopt := range lopts {
84
+ if elem .UserDefinedProtoType != "" {
85
+ line += " |"
86
+ continue
87
+ }
88
+ formatSt := " %s |"
89
+ if elem .Repeated {
90
+ formatSt = " (slice of) %s |"
91
+ }
92
+ switch lopt {
93
+ case "C++" :
94
+ line += fmt .Sprintf (formatSt , elem .ProtoType .Cpp ())
95
+ case "Java" :
96
+ line += fmt .Sprintf (formatSt , elem .ProtoType .Java ())
97
+ case "Python" :
98
+ line += fmt .Sprintf (formatSt , elem .ProtoType .Python ())
99
+ case "Go" :
100
+ line += fmt .Sprintf (formatSt , elem .ProtoType .Go ())
101
+ case "Ruby" :
102
+ line += fmt .Sprintf (formatSt , elem .ProtoType .Ruby ())
103
+ case "C#" :
104
+ line += fmt .Sprintf (formatSt , elem .ProtoType .Csharp ())
105
+ default :
106
+ return fmt .Errorf ("%q is unknown (must be C++, Java, Python, Go, Ruby, C#)" , lopt )
107
+ }
100
108
}
109
+ buf .WriteString (line + "\n " )
101
110
}
102
- buf .WriteString (line + "\n " )
111
+ } else {
112
+ buf .WriteString ("Empty field.\n " )
103
113
}
114
+
104
115
buf .WriteString ("\n \n <br>\n \n " )
105
116
}
106
117
0 commit comments