MCPcopy Create free account
hub / github.com/apache/dubbo-go / Encode

Method Encode

protocol/triple/openapi/encoder.go:39–61  ·  view source on GitHub ↗
(openAPI *model.OpenAPI, format string, pretty bool)

Source from the content-addressed store, hash-verified

37}
38
39func (e *Encoder) Encode(openAPI *model.OpenAPI, format string, pretty bool) (string, error) {
40 if openAPI == nil {
41 openAPI = model.NewOpenAPI()
42 }
43
44 data := e.toMap(openAPI)
45
46 switch strings.ToLower(format) {
47 case "json", "":
48 if pretty {
49 b, err := json.MarshalIndent(data, "", " ")
50 return string(b), err
51 }
52 b, err := json.Marshal(data)
53 return string(b), err
54 case "yaml", "yml":
55 b, err := yaml.Marshal(data)
56 return string(b), err
57 default:
58 b, err := json.Marshal(data)
59 return string(b), err
60 }
61}
62
63func (e *Encoder) toMap(openAPI *model.OpenAPI) map[string]any {
64 result := make(map[string]any)

Calls 3

toMapMethod · 0.95
NewOpenAPIFunction · 0.92
MarshalMethod · 0.65