millennium package - github.com/fabiomatavelli/millennium-go - Go Packages

millennium

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 12 Imported by: 0

README

Millennium Go

Test 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 e suas dependências.

Exemplo

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

package main

import (
	"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.NewClient(context.Background(), "http://192.168.1.1:6017", 30)

  // Login utilizando a sessão do Millennium
  err := client.Login("usuario", "senha", millennium.Session)
  if err != nil {
    panic(err)
  }

  total, err := client.Get("millenium.filiais.lista", url.Values{}, &filiais)

  if err != nil {
    panic(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

View Source
const (
	RetryMax = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthType

type AuthType string

AuthType Millennium authentication type

const (
	NTLM    AuthType = "NTLM"
	Basic   AuthType = "BASIC"
	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 points to retryable http lib
	Client *retryablehttp.Client

	// Context
	Context context.Context

	Timeout time.Duration
	// contains filtered or unexported fields
}

Millennium struct has the essential information to communicate with Millennium ERP

func Client deprecated

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

Deprecated: just for backward compatibility

func NewClient added in v1.1.0

func NewClient(ctx context.Context, server string, timeout time.Duration) (*Millennium, error)

NewClient returns a new Millennium instance with the server address and timeout

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