postman

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

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",
		},
	},
}

ts := httptest.NewServer(http.HandlerFunc(HandleCollection(Parse(cfg))))
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])
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
{Name:/foo Request:{URL:{Raw:{{SCHEMA}}://{{HOST}}/foo Protocol:{{SCHEMA}} Host:[{{HOST}}] Path:[foo]} Method:GET Header:[] Body:<nil> Description:}}
2
HOST
localhost:8080
string
SCHEMA
http
string

Types

type Body

type Body struct {
	Mode string `json:"mode,omitempty"`
	Raw  string `json:"raw,omitempty"`
}

type Collection

type Collection struct {
	Variables []Variable `json:"variables"`
	Info      Info       `json:"info"`
	Item      []Item     `json:"item"`
}

func Parse

func Parse(cfg config.ServiceConfig) Collection

Parse converts the received service config into a simple POSTMAN collection description

Example
c := Parse(config.ServiceConfig{
	Port: 8080,
	Name: "sample",
	Endpoints: []*config.EndpointConfig{
		{
			Endpoint: "/foo",
			Method:   "GET",
		},
		{
			Endpoint: "/bar",
			Method:   "POST",
		},
	},
})
fmt.Println(c.Info.Name)
fmt.Println(c.Info.Schema)
fmt.Println(len(c.Item))
fmt.Printf("%+v\n", c.Item[0])
fmt.Printf("%+v\n", c.Item[1])
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
2
{Name:/foo Request:{URL:{Raw:{{SCHEMA}}://{{HOST}}/foo Protocol:{{SCHEMA}} Host:[{{HOST}}] Path:[foo]} Method:GET Header:[] Body:<nil> Description:}}
{Name:/bar Request:{URL:{Raw:{{SCHEMA}}://{{HOST}}/bar Protocol:{{SCHEMA}} Host:[{{HOST}}] Path:[bar]} Method:POST Header:[] Body:<nil> Description:}}
2
HOST
localhost:8080
string
SCHEMA
http
string
type Header []struct {
	Key         string `json:"key"`
	Value       string `json:"value"`
	Description string `json:"description,omitempty"`
}

type Info

type Info struct {
	Name        string `json:"name"`
	PostmanID   string `json:"_postman_id"`
	Description string `json:"description,omitempty"`
	Schema      string `json:"schema"`
}

type Item

type Item struct {
	Name    string  `json:"name"`
	Request Request `json:"request"`
}

type Request

type Request struct {
	URL         URL      `json:"url"`
	Method      string   `json:"method"`
	Header      []Header `json:"header,omitempty"`
	Body        *Body    `json:"body,omitempty"`
	Description string   `json:"description,omitempty"`
}

type URL

type URL struct {
	Raw      string   `json:"raw"`
	Protocol string   `json:"protocol"`
	Host     []string `json:"host"`
	Path     []string `json:"path"`
}

type Variable

type Variable struct {
	ID    string `json:"id"`
	Key   string `json:"key"`
	Value string `json:"value"`
	Type  string `json:"type"`
}

Directories

Path Synopsis
cmd
krakend-postman command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL