millennium

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2018 License: MIT Imports: 11 Imported by: 0

README

Millennium Go

Build Status Maintainability Test Coverage Go Report Card FOSSA Status

Esta biblioteca tem o intuito de facilitar a integração com o ERP Millennium utilizando Go.

Instalação

Para começar a utilizar o Millennium com Go, instale o Go e rode o go get:

go get -u github.com/fabiomatavelli/millennium-go

Isso irá baixar a instalar a biblioteca.

Exemplo

No exemplo abaixo, iremos listar todas as filiais cadastradas no Millennium

package main

import (
	millennium "github.com/fabiomatavelli/millennium-go"
)

type Filial struct {
  Filial int    `json:"filial"`
  Codigo string `json:"cod_filial"`
  Nome   string `json:"nome"`
  CNPJ   string `json:"cnpj"`
}

func main() {
  var filiais []Filial
  client := millennium.Client("http://192.168.1.1:6017", 30)
  
  // Login utilizando a sessão do Millennium
  client.Login("usuario", "senha", millennium.Session)

  total, err := client.Get("millenium.filiais.lista", url.Values{}, &filiais)
  
  if err != nil {
    fmt.Print(err)
  }

  if total > 0 {
    for _, filial := range filiais {
      fmt.Printf("Filial: %s CNPJ: %s", filial.Nome, filial.CNPJ)
    }
  }
}

License

FOSSA Status

Documentation

Overview

Package millennium is a Millennium ERP library written in Go to facilitate the integration with Millennium ERP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthType

type AuthType string

AuthType Millennium authentication type

const (
	NTLM    AuthType = "NTLM"
	Session AuthType = "SESSION"
)

Authentication types available for Millennium

type HTTPMethod

type HTTPMethod string

HTTPMethod type to communicate with Millennium

const (
	GET    HTTPMethod = "GET"
	POST   HTTPMethod = "POST"
	DELETE HTTPMethod = "DELETE"
)

HTTP methods available

type Millennium

type Millennium struct {
	// Server used to store the server address
	ServerAddr string

	// Client HTTP
	Client *http.Client
	// contains filtered or unexported fields
}

Millennium struct has the essential information to communicate with Millennium ERP

func Client

func Client(server string, timeout time.Duration) (*Millennium, error)

Client returns a new Millennium instance with the server address

func (*Millennium) Delete

func (m *Millennium) Delete(method string, params url.Values) error

Delete requests a method using DELETE http method

func (*Millennium) Get

func (m *Millennium) Get(method string, params url.Values, response interface{}) (int, error)

Get requests a method using GET http method

func (*Millennium) Login

func (m *Millennium) Login(username string, password string, authType AuthType) error

Login requests login to Millennium server server should be a valid URL with Millennium port, like: https://127.0.0.1:6018

func (*Millennium) Post

func (m *Millennium) Post(method string, body []byte, response interface{}) error

Post requests a method using POST http method

func (*Millennium) Request

func (m *Millennium) Request(r RequestMethod) (err error)

Request a method from Millennium

type RequestMethod

type RequestMethod struct {
	HTTPMethod HTTPMethod
	Method     string
	Params     url.Values
	Body       []byte
	Response   interface{}
}

RequestMethod receive data to pass to Request function

type ResponseError

type ResponseError struct {
	Err struct {
		Code    int `json:"code"`
		Message struct {
			Lang  string `json:"lang"`
			Value string `json:"value"`
		} `json:"message"`
	} `json:"error"`
}

ResponseError type is the standard response struct for errors

func (*ResponseError) Error

func (r *ResponseError) Error() string

func (*ResponseError) SetCode

func (r *ResponseError) SetCode(code int)

SetCode sets a custom error code

func (*ResponseError) SetMessage

func (r *ResponseError) SetMessage(message string)

SetMessage sets a custom error message

func (*ResponseError) String

func (r *ResponseError) String() string

type ResponseGet

type ResponseGet struct {
	Count int              `json:"odata.count"`
	Value *json.RawMessage `json:"value"`
}

ResponseGet type is the standard response struct from GET requests

type ResponseLogin

type ResponseLogin struct {
	Session string `json:"session"`
}

ResponseLogin type is the standard response struct from login requests

Jump to

Keyboard shortcuts

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