Giter Site home page Giter Site logo

fabiomatavelli / millennium-go Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 83 KB

Cliente em Go para comunicação com o ERP Linx e-Millennium - https://e-millennium.com.br/

License: MIT License

Go 99.81% Makefile 0.19%
millennium biblioteca library e-commerce go golang linx sdk e-millennium emillennium

millennium-go's Introduction

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

millennium-go's People

Contributors

dependabot[bot] avatar fabiomatavelli avatar fossabot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

fossabot

millennium-go's Issues

Fix empty url parameters

When runningRequest without Params defined, the error assignment to entry in nil map is returned.

Validate parameters

The following parameters from type RequestMethod are not validated before request:

  • HTTPMethod
  • Body
  • Response

It would be better to validate them to ensure that the request will be successful.

Check errors from NewRequest before anything

After run http.NewRequest, check for errors before anything.

// Start a new request
req, err := http.NewRequest(string(r.HTTPMethod), fmt.Sprintf("%s/api/%s?%s", m.ServerAddr, r.Method, r.Params.Encode()), bodyReader)
if m.headers != nil {
	req.Header = m.headers
}

if err != nil {
	return err
}

Should be:

// Start a new request
req, err := http.NewRequest(string(r.HTTPMethod), fmt.Sprintf("%s/api/%s?%s", m.ServerAddr, r.Method, r.Params.Encode()), bodyReader)
if err != nil {
	return err
}

if m.headers != nil {
	req.Header = m.headers
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.