paperfishGo

package module
v0.0.0-...-292d253 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: MPL-2.0 Imports: 24 Imported by: 0

README

paperfishGo

RESTfull client for the Go language.

The swagger client is almost complete, but not extensively tested. The API is almost stabilized and changes, now, is not likely to occur, except if we face some unpredicted big problem and, even in this case, we'll do our best efforts to make any change as small as possible. HTTP methods implemented are GET and POST only, others will come soon. So, consider it beta code in respect to GET and PUT methods.

The SOAP client is very alpha code and not suitable even for tests. So, consider this part of the software for study purposes only.

Example

   httpclient = &http.Client{
      Transport:  &http.Transport{
         TLSClientConfig:     <some TLS configuratio>,
         // Any other configuration that fits to your needs
      },
   }

   ws, err = paperfishGo.NewFromURL("https://your.host/swagger.json",httpclient)
   if err != nil {
      fmt.Printf("Error fetching swagger: %s\n",err)
      return err
   }

   // Example below assumes that your.host offers an operation identified by "someOperationId"
   // which was defined using HTTP POST method
   httpStatus, err = ws.Post("someOperationId", map[string]interface{}{
      // Any parameters needed by the "someOperationId" operation
      .
      .
      .
   }, &resp)
   if err != nil {
      fmt.Printf("Error: %s\n",err)
      return err
   }

   fmt.Printf("Response: %d [%s]\n", httpStatus, resp)

   // Example below assumes that your.host offers an operation identified by "anotherOperationId"
   // which was defined using HTTP GET method
   httpStatus, err = ws.Get("anotherOperationId", map[string]interface{}{
      // Any parameters needed by the "anotherOperationId" operation
      .
      .
      .
   }, &id)
   if err != nil {
      fmt.Printf("Erro fazendo upload do pdf: %s\n",err)
      return
   }

   fmt.Printf("Response: %d [%d]\n", httpStatus, id)

   // Example below assumes that your.host offers an operation identified by "yetAnotherOperationId"
   // which was defined using HTTP GET method and starts a websocket connection which defines an
   // event called websocketEventId
   httpStatus, err = ws.Get("yetAnotherOperationId", map[string]interface{}{
      // Any parameters needed by the "yetAnotherOperationId" operation
      .
      .
      .
   }, &wsock)
   if err != nil {
      fmt.Printf("Error connecting to websocket yetAnotherOperationId: %s\n",err)
      return
   }

   fmt.Printf("Response: %d [%d]\n", httpStatus, *wsock)

   wg.Add(1)

   wsock.On("websocketEventId",func(<parameters are the data sent by the server event>){
      // Code to execute whenever the event fires
      .
      .
      .
   })

   wg.Wait()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CliCerts []tls.Certificate
View Source
var ErrBadAddressLocationOfService error = errors.New("Bad address location of service")
View Source
var ErrBuffer error = errors.New("Error writing buffer")
View Source
var ErrEmptyResponse error = errors.New("Empty response")
View Source
var ErrEmptyString error = errors.New("Error empty string")
View Source
var ErrFetchingContract error = errors.New("Error fetching contract")
View Source
var ErrNilHandle error = errors.New("Err nil handle")
View Source
var ErrNoElementFoundOnMessage error = errors.New("no element found on message")
View Source
var ErrParmNotFound error = errors.New("Parameter not found")
View Source
var ErrProtocol error = errors.New("Err protocol syntax error")
View Source
var ErrServer error = errors.New("Err on server")
View Source
var ErrUndetectableType error = errors.New("Error undetectable type")
View Source
var ErrUnknownKind error = errors.New("Error unknown kind")
View Source
var ErrUnknownMethod error = errors.New("Error unknown method")
View Source
var ErrUnknownMimeType error = errors.New("Error unknown mimetype")
View Source
var ErrUnknownOperation error = errors.New("Error unknown operation")
View Source
var ErrWrite error = errors.New("Error writing stream")
View Source
var ErrWrongParmCount error = errors.New("Wrong parameter count")
View Source
var ErrWrongParmType error = errors.New("Wrong parameter type")
View Source
var ErrWrongReturnParmType error = errors.New("Wrong return parameter type")
View Source
var Fake bool // Se true, não vai acessar web service, vai usar arquivos XML locais
View Source
var IndentPrefix string = "   "
View Source
var RootCAs *x509.CertPool
View Source
var TagsT []string

Whenever you add a new struct or new field to handle a xml tag, you must add the tag name in TagsT slice

Functions

func Exported

func Exported(s string) (string, error)

func GetCoder

func GetCoder(mime []string) (interface{}, error)

func NewTrackId

func NewTrackId() (string, error)

func NewWSTrackId

func NewWSTrackId() (uint32, error)

func Set

func Set(v reflect.Value, val reflect.Value)

Types

type Address

type Address struct {
	Location string `xml:"location,attr"`
}

type AttributeT

type AttributeT struct {
	Name string `xml:"name,attr"`
	Type string `xml:"type,attr"`
	Use  string `xml:"use,attr"`
}

type Base64Binary

type Base64Binary []byte

func (Base64Binary) MarshalXML

func (bb Base64Binary) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type Base64Hnd

type Base64Hnd struct{}

func (Base64Hnd) Decode

func (Hand Base64Hnd) Decode(r io.Reader, v interface{}) error

func (Base64Hnd) Encode

func (Hand Base64Hnd) Encode(w *bytes.Buffer, nm string, v interface{}, isTail bool) error

type BinaryHnd

type BinaryHnd struct{}

func (BinaryHnd) Decode

func (Hand BinaryHnd) Decode(r io.Reader, v interface{}) error

func (BinaryHnd) Encode

func (Hand BinaryHnd) Encode(w *bytes.Buffer, nm string, v interface{}, isTail bool) error

type BindingT

type BindingT struct {
	Name              string               `xml:"name,attr"`
	Type              string               `xml:"type,attr"`
	Protocol          ProtocolBinding      `xml:"binding"`
	ConcreteOperation []ConcreteOperationT `xml:"operation"`
}

type CallbackT

type CallbackT struct {
	Callback     reflect.Value
	FailCallback func(int)
}

type ComplexTypeT

type ComplexTypeT struct {
	Name          string           `xml:"name,attr"`
	Sequence      []ElementT       `xml:"sequence>element"`
	ExtensionBase []ExtensionBaseT `xml:"complexContent>extension"`
	Attribute     []AttributeT     `xml:"attribute"`
}

type ConcreteOperationT

type ConcreteOperationT struct {
	Name      string           `xml:"name,attr"`
	Operation OperationBinding `xml:"operation"`

	InputSOAP  SoapBody `xml:"input>body"`
	OutputSOAP SoapBody `xml:"output>body"`

	InputHTTP  HTTPContent `xml:"input>content"`
	OutputHTTP HTTPContent `xml:"output>content"`
}

type Decoder

type Decoder interface {
	Decode(io.Reader, interface{}) error
}

type ElementT

type ElementT struct {
	Name          string         `xml:"name,attr"`
	Type          string         `xml:"type,attr"`
	Documentation string         `xml:"annotation>documentation"`
	Nillable      string         `xml:"nillable,attr"`
	MaxOccurs     string         `xml:"maxOccurs,attr"`
	MinOccurs     string         `xml:"minOccurs,attr"`
	ComplexTypes  []ComplexTypeT `xml:"complexType"`
}

TODO: fazer algum processamento para a partir da string nillable (true ou false) para boolean go

type Encoder

type Encoder interface {
	Encode(output *bytes.Buffer, name string, val interface{}, isTail bool) error
}

type Endpoint

type Endpoint struct {
	Name string  `xml:"name,attr"`
	Port []PortT `xml:"port"`
}

type EnumerationT

type EnumerationT struct {
	Value string `xml:"value,attr"`
}

type ExtensionBaseT

type ExtensionBaseT struct {
	Base     string     `xml:"base,attr"`
	Sequence []ElementT `xml:"sequence>element"`
}

type FormDataHnd

type FormDataHnd struct{}

type FormURLHnd

type FormURLHnd struct{}

func (FormURLHnd) Decode

func (Hand FormURLHnd) Decode(r io.Reader, v interface{}) error

func (FormURLHnd) Encode

func (Hand FormURLHnd) Encode(w *bytes.Buffer, nm string, v interface{}, isTail bool) error

type GoUnmarshal

type GoUnmarshal WSDLStruct

Created only to cast the variables inside customized XML Unmarshal methods

type GoUnmarshalMessage

type GoUnmarshalMessage Message

type GoUnmarshalSchema

type GoUnmarshalSchema SchemaT

type GooseG

type GooseG struct {
	New   goose.Alert
	Fetch goose.Alert
	Set   goose.Alert
	Type  goose.Alert
}
var Goose GooseG

type HTTPContent

type HTTPContent struct {
	Type string `xml:"type,attr"`
}

type ImportT

type ImportT struct {
	SchemaLocation string `xml:"schemaLocation,attr"`
	NameSpace      string `xml:"namespace,attr"`
}

type JsonHnd

type JsonHnd struct{}

func (JsonHnd) Decode

func (Hand JsonHnd) Decode(r io.Reader, v interface{}) error

func (JsonHnd) Encode

func (Hand JsonHnd) Encode(w *bytes.Buffer, nm string, v interface{}, isTail bool) error

type ListT

type ListT struct {
	ItemType string `xml:"itemType,attr"`
}

type Message

type Message struct {
	Name             string `xml:"message,attr"`
	Namespace        map[string]string
	NamespaceReverse map[string]string
}

TODO: fazer algum processamento para preencher os vetores de parâmetros a partir do nome das mensagens

type MessageT

type MessageT struct {
	Name string `xml:"name,attr"`
	Part PartT  `xml:"part"`
}

type ModData

type ModData struct {
	Type   reflect.Type
	Schema *stonelizard.SwaggerSchemaT
}

type Operation

type Operation struct {
	Name   string  `xml:"name,attr"`
	Input  Message `xml:"input"`
	Output Message `xml:"output"`
}

type OperationBinding

type OperationBinding struct {
	SoapAction string `xml:"soapAction,attr"`
	Style      string `xml:"style,attr"`

	Location string `xml:"location,attr"`
}

type OperationT

type OperationT struct {
	Path    string
	Schemes []string
	Encoder Encoder
	Decoder Decoder

	Output        map[int]*ParameterT
	PathParm      []*ParameterT
	HeaderParm    []*ParameterT
	QueryParm     []*ParameterT
	BodyParm      *ParameterT
	FormParm      []*ParameterT
	SubOperations map[string]*SubOperationT
	XModule       string
	XOutput       string
	XOutputVar    string
	// contains filtered or unexported fields
}

type ParameterT

type ParameterT struct {
	Name       string
	Kind       reflect.Kind
	Type       reflect.Type
	Title      string
	Schema     *stonelizard.SwaggerSchemaT
	Properties map[string]stonelizard.SwaggerSchemaT
}

type PartT

type PartT struct {
	Element string `xml:"element,attr"`
	Name    string `xml:"name,attr"`
}

type PortT

type PortT struct {
	Binding string  `xml:"binding,attr"`
	Name    string  `xml:"name,attr"`
	Address Address `xml:"address"`
}

type ProtocolBinding

type ProtocolBinding struct {
	Style     string `xml:"style,attr"`
	Transport string `xml:"transport,attr"`

	Verb string `xml:"verb,attr"`
}

type RestrictionBaseT

type RestrictionBaseT struct {
	Base        string         `xml:"base,attr"`
	Enumeration []EnumerationT `xml:"enumeration"`
}

type SchemaT

type SchemaT struct {
	AttributeFormDefault string     `xml:"attributeFormDefault,attr"`
	ElementFormDefault   string     `xml:"elementFormDefault,attr"`
	TargetNamespace      string     `xml:"targetNamespace,attr"`
	XMLAttr              []xml.Attr `xml:",any,attr"`
	Namespace            map[string]string
	NamespaceReverse     map[string]string
	Import               []ImportT      `xml:"import"`
	Elements             []ElementT     `xml:"element"`
	SimpleTypes          []SimpleTypeT  `xml:"simpleType"`
	ComplexTypes         []ComplexTypeT `xml:"complexType"`
}

type SimpleTypeT

type SimpleTypeT struct {
	Name            string           `xml:"name,attr"`
	RestrictionBase RestrictionBaseT `xml:"restriction"`
	List            ListT            `xml:"list"`
}

type SoapBody

type SoapBody struct {
	Use  string `xml:"use,attr"`
	Type string `xml:"type,attr"`
}

type SoapBodyT

type SoapBodyT struct {
	XMLName xml.Name
	Data    interface{}
}

type SoapData

type SoapData interface {
	SetName(nm string, attr []xml.Attr) interface{}
}

type SoapLiteralHnd

type SoapLiteralHnd struct {
	Conv func(string) string
	// contains filtered or unexported fields
}

func (SoapLiteralHnd) Decode

func (Hand SoapLiteralHnd) Decode(r io.Reader, v interface{}) error

func (SoapLiteralHnd) Encode

func (Hand SoapLiteralHnd) Encode(w *bytes.Buffer, nm string, v interface{}, isTail bool) error

type SubOperationT

type SubOperationT struct {
	Id    string
	Parms []*ParameterT
}

type TextHnd

type TextHnd struct {
	// contains filtered or unexported fields
}

func (TextHnd) Decode

func (Hand TextHnd) Decode(r io.Reader, v interface{}) error

func (TextHnd) Encode

func (Hand TextHnd) Encode(w *bytes.Buffer, nm string, v interface{}, isTail bool) error

type WSClientT

type WSClientT struct {
	Host     string
	BasePath string
	Binding  string
	Schemes  []string
	Modules  map[string]map[string]ModData

	TargetNamespace  string
	Xmlns            map[string]string
	Encoder          Encoder
	Decoder          Decoder
	Client           *http.Client
	GetOperation     map[string]*OperationT
	PostOperation    map[string]*OperationT
	PutOperation     map[string]*OperationT
	DeleteOperation  map[string]*OperationT
	OptionsOperation map[string]*OperationT
	HeadOperation    map[string]*OperationT
	PatchOperation   map[string]*OperationT
	// contains filtered or unexported fields
}

func NewFromReader

func NewFromReader(contract io.Reader, client *http.Client) ([]WSClientT, error)

func NewFromURL

func NewFromURL(uri string, client *http.Client) ([]WSClientT, error)

func NewFromURL(url string, client *http.Client) (map[string]Operation, error) {

func (*WSClientT) Get

func (ws *WSClientT) Get(opName string, input map[string]interface{}, output interface{}) (int, error)

func (*WSClientT) Post

func (ws *WSClientT) Post(opName string, input map[string]interface{}, output interface{}) (int, error)

func (WSClientT) RedefineType

func (ws WSClientT) RedefineType(typeName, typeDef string) error

func (*WSClientT) SetConv

func (ws *WSClientT) SetConv(fn func(string) string, targets ...interface{}) error

func (*WSClientT) SetEndPoint

func (ws *WSClientT) SetEndPoint(endpoint string, targets ...interface{}) error

func (WSClientT) Types

func (ws WSClientT) Types(pkg string) string

type WSDLStruct

type WSDLStruct struct {
	TargetNamespace  string     `xml:"targetNamespace,attr"`
	XMLAttr          []xml.Attr `xml:",any,attr"`
	Namespace        map[string]string
	NamespaceReverse map[string]string
	Documentation    string      `xml:"documentation"`
	Message          []MessageT  `xml:"message"`
	PortType         []Operation `xml:"portType>operation"`
	Binding          []BindingT  `xml:"binding"`
	Service          []Endpoint  `xml:"service"`
	Types            []SchemaT   `xml:"types>schema"`
}

type WSResponse

type WSResponse map[string]interface{}

type Operation = func(map[string]interface{}) (interface{},error)

type WSockClientT

type WSockClientT struct {
	SubOperations map[string]*SubOperationT
	// contains filtered or unexported fields
}

func (*WSockClientT) On

func (wsc *WSockClientT) On(evtName string, fn interface{}) error

func (*WSockClientT) Send

func (wsc *WSockClientT) Send(opName string, params map[string]interface{}, fn interface{}, fnfail func(int)) error

func (*WSockClientT) SendSync

func (wsc *WSockClientT) SendSync(opName string, params map[string]interface{}, fn interface{}, fnfail func(int)) error

type WSockRequest

type WSockRequest struct {
	SubOperation string
	Params       []interface{}
	CallbackT
}

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func (Writer) Write

func (w Writer) Write(p []byte) (int, error)

type XMLnsT

type XMLnsT struct {
	Alias string
	Value string `xml:"xmlns,attr"`
}

TODO: fazer algum processamento para quebrar a string e pegar os valores corretos para o alias e para o value

type XmlHnd

type XmlHnd struct{}

type Xop

type Xop string

func (*Xop) UnmarshalXML

func (x *Xop) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type XopHnd

type XopHnd struct{}

type XsdSymT

type XsdSymT struct {
	reflect.Type
	// contains filtered or unexported fields
}

func (XsdSymT) Name

func (xs XsdSymT) Name() string

type XsdSymTabT

type XsdSymTabT map[string]*XsdSymT

Jump to

Keyboard shortcuts

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