go-postman-collection: github.com/rbretecher/go-postman-collection Index | Files

package postman

import "github.com/rbretecher/go-postman-collection"

Index

Package Files

auth.go body.go collection.go header.go items.go method.go request.go url.go variable.go

Constants

const (
    // APIKey stands for API Key Authentication.
    APIKey authType = "apikey"
    // AWSV4 is Amazon AWS Authentication.
    AWSV4 authType = "awsv4"
    // Basic Authentication.
    Basic authType = "basic"
    // Bearer Token Authentication.
    Bearer authType = "bearer"
    // Digest Authentication.
    Digest authType = "digest"
    // Hawk Authentication.
    Hawk authType = "hawk"
    // NoAuth Authentication.
    NoAuth authType = "noauth"
    // OAuth1 Authentication.
    OAuth1 authType = "oauth1"
    // OAuth2 Authentication.
    OAuth2 authType = "oauth2"
    // NTLM Authentication.
    NTLM authType = "ntlm"
)
const (
    // V210 : v2.1.0
    V210 version = "v2.1.0"
    // V200 : v2.0.0
    V200 version = "v2.0.0"
)
const (
    // Get HTTP method.
    Get method = "GET"
    // Put HTTP method.
    Put method = "PUT"
    // Post HTTP method.
    Post method = "POST"
    // Patch HTTP method.
    Patch method = "PATCH"
    // Delete HTTP method.
    Delete method = "DELETE"
    // Copy HTTP method.
    Copy method = "COPY"
    // Head HTTP method.
    Head method = "HEAD"
    // Options HTTP method.
    Options method = "OPTIONS"
    // Link HTTP method.
    Link method = "LINK"
    // Unlink HTTP method.
    Unlink method = "UNLINK"
    // Purge HTTP method.
    Purge method = "PURGE"
    // Lock HTTP method.
    Lock method = "LOCK"
    // Unlock HTTP method.
    Unlock method = "UNLOCK"
    // Propfind HTTP method.
    Propfind method = "PROPFIND"
    // View HTTP method.
    View method = "VIEW"
)

type Auth Uses

type Auth authV210

Auth contains the authentication method used and its associated parameters.

func CreateAuth Uses

func CreateAuth(a authType, params ...*AuthParam) *Auth

CreateAuth creates a new Auth struct with the given parameters.

func (Auth) GetParams Uses

func (a Auth) GetParams() []*AuthParam

GetParams returns the parameters related to the authentication method in use.

func (Auth) MarshalJSON Uses

func (a Auth) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of a Auth. If the version is v2.0.0 it is returned as an object, otherwise as an array (v2.1.0).

func (*Auth) UnmarshalJSON Uses

func (a *Auth) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON parses the JSON-encoded data and create an Auth from it. Depending on the Postman Collection version, an auth property can either be an array or an object.

- v2.1.0 : Array
- v2.0.0 : Object

type AuthParam Uses

type AuthParam struct {
    Key   string      `json:"key,omitempty"`
    Value interface{} `json:"value,omitempty"`
    Type  string      `json:"type,omitempty"`
}

AuthParam represents an attribute for any authentication method provided by Postman. For example "username" and "password" are set as auth attributes for Basic Authentication method.

func CreateAuthParam Uses

func CreateAuthParam(key string, value string) *AuthParam

CreateAuthParam creates a new AuthParam of type string.

type Body Uses

type Body struct {
    Mode       string      `json:"mode"`
    Raw        string      `json:"raw,omitempty"`
    URLEncoded interface{} `json:"urlencoded,omitempty"`
    FormData   interface{} `json:"formdata,omitempty"`
    File       interface{} `json:"file,omitempty"`
    GraphQL    interface{} `json:"graphql,omitempty"`
    Disabled   bool        `json:"disabled,omitempty"`
}

Body represents the data usually contained in the request body.

type Collection Uses

type Collection struct {
    Info      Info        `json:"info"`
    Items     []*Items    `json:"item"`
    Variables []*Variable `json:"variable,omitempty"`
}

Collection represents a Postman Collection.

func CreateCollection Uses

func CreateCollection(name string, desc string) *Collection

CreateCollection returns a new Collection.

func ParseCollection Uses

func ParseCollection(r io.Reader) (c *Collection, err error)

ParseCollection parses the content of the provided data stream into a Collection object.

func (*Collection) AddItem Uses

func (c *Collection) AddItem(item *Items)

AddItem appends an item (Item or ItemGroup) to the existing items slice.

func (*Collection) AddItemGroup Uses

func (c *Collection) AddItemGroup(name string) (f *Items)

AddItemGroup creates a new ItemGroup and appends it to the existing items slice.

func (*Collection) Write Uses

func (c *Collection) Write(w io.Writer, v version) (err error)

Write encodes the Collection struct in JSON and writes it into the provided io.Writer.

type Header struct {
    Key         string `json:"key"`
    Value       string `json:"value"`
    Disabled    bool   `json:"disabled,omitempty"`
    Description string `json:"description,omitempty"`
}

Header represents an HTTP Header.

type Info Uses

type Info struct {
    Name        string `json:"name"`
    Description string `json:"description"`
    Version     string `json:"version"`
    Schema      string `json:"schema"`
}

Info stores data about the collection.

type Item Uses

type Item struct {
    Name                    string      `json:"name"`
    Description             string      `json:"description,omitempty"`
    Variables               []*Variable `json:"variable,omitempty"`
    Event                   interface{} `json:"event,omitempty"`
    ProtocolProfileBehavior interface{} `json:"protocolProfileBehavior,omitempty"`
    ID                      string      `json:"id,omitempty"`
    Request                 *Request    `json:"request,omitempty"`
    Response                interface{} `json:"response,omitempty"`
}

An Item is an entity which contain an actual HTTP request, and sample responses attached to it.

type ItemGroup Uses

type ItemGroup struct {
    Name                    string      `json:"name"`
    Description             string      `json:"description,omitempty"`
    Variables               []*Variable `json:"variable,omitempty"`
    Event                   interface{} `json:"event,omitempty"`
    ProtocolProfileBehavior interface{} `json:"protocolProfileBehavior,omitempty"`
    Items                   []*Items    `json:"item"`
    Auth                    *Auth       `json:"auth,omitempty"`
}

A ItemGroup is an ordered set of requests.

type Items Uses

type Items struct {
    // Common fields.
    Name                    string      `json:"name"`
    Description             string      `json:"description,omitempty"`
    Variables               []*Variable `json:"variable,omitempty"`
    Event                   interface{} `json:"event,omitempty"`
    ProtocolProfileBehavior interface{} `json:"protocolProfileBehavior,omitempty"`
    // Fields specific to Item
    ID       string      `json:"id,omitempty"`
    Request  *Request    `json:"request,omitempty"`
    Response interface{} `json:"response,omitempty"`
    // Fields specific to ItemGroup
    Items []*Items `json:"item"`
    Auth  *Auth    `json:"auth,omitempty"`
}

Items are the basic unit for a Postman collection. It can either be a request (Item) or a folder (ItemGroup).

func CreateItem Uses

func CreateItem(i Item) *Items

CreateItem is a helper to create a new Item.

func CreateItemGroup Uses

func CreateItemGroup(ig ItemGroup) *Items

CreateItemGroup is a helper to create a new ItemGroup.

func (*Items) AddItem Uses

func (i *Items) AddItem(item *Items)

AddItem appends an item to the existing items slice.

func (*Items) AddItemGroup Uses

func (i *Items) AddItemGroup(name string) (f *Items)

AddItemGroup creates a new Item folder and appends it to the existing items slice.

func (Items) IsGroup Uses

func (i Items) IsGroup() bool

IsGroup returns false as an Item is not a group.

func (Items) MarshalJSON Uses

func (i Items) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of an Item/ItemGroup.

type Request Uses

type Request struct {
    URL         *URL        `json:"url"`
    Auth        *Auth       `json:"auth,omitempty"`
    Proxy       interface{} `json:"proxy,omitempty"`
    Certificate interface{} `json:"certificate,omitempty"`
    Method      method      `json:"method"`
    Description interface{} `json:"description,omitempty"`
    Header      []*Header   `json:"header,omitempty"`
    Body        *Body       `json:"body,omitempty"`
}

A Request represents an HTTP request.

func CreateRequest Uses

func CreateRequest(u string, m method) *Request

CreateRequest creates a new request.

func (Request) MarshalJSON Uses

func (r Request) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of a Request. If the Request only contains an URL with the Get HTTP method, it is returned as a string.

func (*Request) UnmarshalJSON Uses

func (r *Request) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON parses the JSON-encoded data and create a Request from it. A Request can be created from an object or a string. If a string, the string is assumed to be the request URL and the method is assumed to be 'GET'.

type URL Uses

type URL struct {
    Raw       string      `json:"raw"`
    Protocol  string      `json:"protocol,omitempty"`
    Host      []string    `json:"host,omitempty"`
    Path      []string    `json:"path,omitempty"`
    Port      string      `json:"port,omitempty"`
    Query     interface{} `json:"query,omitempty"`
    Hash      string      `json:"hash,omitempty"`
    Variables []*Variable `json:"variable,omitempty" mapstructure:"variable"`
    // contains filtered or unexported fields
}

URL is a struct that contains an URL in a "broken-down way". Raw contains the complete URL.

func (URL) MarshalJSON Uses

func (u URL) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of an URL. It encodes the URL as a string if it does not contain any variable. In case it contains any variable, it gets encoded as an object.

func (URL) String Uses

func (u URL) String() string

String returns the raw version of the URL.

func (*URL) UnmarshalJSON Uses

func (u *URL) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON parses the JSON-encoded data and create an URL from it. An URL can be created from an object or a string. If a string, the value is assumed to be the Raw attribute of the URL.

type Variable Uses

type Variable struct {
    ID          string `json:"id,omitempty"`
    Key         string `json:"key,omitempty"`
    Type        string `json:"type,omitempty"`
    Name        string `json:"name,omitempty"`
    Value       string `json:"value,omitempty"`
    Description string `json:"description,omitempty"`
    System      bool   `json:"system,omitempty"`
    Disabled    bool   `json:"disabled,omitempty"`
}

A Variable allows you to store and reuse values in your requests and scripts.

func CreateVariable Uses

func CreateVariable(name string, value string) *Variable

CreateVariable creates a new Variable of type string.

Package postman imports 4 packages (graph). Updated 2020-04-02. Refresh now. Tools for package owners.