Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleCollection ¶
func HandleCollection(c Collection) func(http.ResponseWriter, *http.Request)
HandleCollection returns a simple http.HandleFunc exposing the POSTMAN collection description
Example ¶
cfg := config.ServiceConfig{ Port: 8080, Name: "sample", Endpoints: []*config.EndpointConfig{ { Endpoint: "/foo", Method: "GET", }, }, } parsedConfig, _ := Parse(cfg) ts := httptest.NewServer(http.HandlerFunc(HandleCollection(parsedConfig))) defer ts.Close() res, err := http.Get(ts.URL) if err != nil { fmt.Println(err.Error()) } c := Collection{} if err := json.NewDecoder(res.Body).Decode(&c); err != nil { fmt.Println(err.Error()) } res.Body.Close() fmt.Println(c.Info.Name) fmt.Println(c.Info.Schema) fmt.Println(len(c.Item)) fmt.Printf("%+v\n", c.Item[0].Name) fmt.Printf("%+v\n", c.Item[0].Item) fmt.Printf("%+v\n", c.Item[0].Request.URL.Raw) fmt.Println(len(c.Variables)) fmt.Printf("%+v\n", c.Variables[0].Key) fmt.Printf("%+v\n", c.Variables[0].Value) fmt.Printf("%+v\n", c.Variables[0].Type) fmt.Printf("%+v\n", c.Variables[1].Key) fmt.Printf("%+v\n", c.Variables[1].Value) fmt.Printf("%+v\n", c.Variables[1].Type)
Output: sample https://schema.getpostman.com/json/collection/v2.1.0/collection.json 1 /foo [] {{SCHEMA}}://{{HOST}}/foo 2 HOST localhost:8080 string SCHEMA http string
Types ¶
type Collection ¶
type Collection struct { Variables []Variable `json:"variables"` Info Info `json:"info"` Item ItemList `json:"item"` }
func Parse ¶
func Parse(cfg config.ServiceConfig) (Collection, error)
Parse converts the received service config into a simple POSTMAN collection description @see https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html
Click to show internal directories.
Click to hide internal directories.