godoo

package module
v0.0.0-...-b1dec96 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Godoo - Odoo RPC Client for Go

Go Report Card GoDoc

Godoo is a Go library that provides a wrapper around the Odoo RPC API, supporting both JSON-RPC and XML-RPC protocols, making it easier to interact with Odoo from your Go applications. JSON-RPC is now the default protocol for compatibility with modern Odoo versions.

Features

  • Support for both JSON-RPC (default) and XML-RPC protocols
  • Connection pooling to efficiently manage connections to your Odoo instance.
  • A simple and intuitive API for calling Odoo methods.
  • Type-safe wrappers for common Odoo data types.
  • Automatic handling of authentication for both protocols.
  • Robust connection management with automatic reconnection.
  • Full compatibility with modern Odoo versions

Installation

To install Godoo, use go get:

go get github.com/wongpinter/godoo

Usage

This project includes three examples in the examples directory:

  1. single_client: A simple example demonstrating how to connect to a single Odoo instance using JSON-RPC (default) and read data.
  2. jsonrpc_client: An example showing how to explicitly use JSON-RPC protocol to connect to Odoo.
  3. rpc_pool: A more advanced example showing how to use the connection pool to manage connections to multiple Odoo instances using JSON-RPC, including automatic reconnection.
Single Client Example

To run the single client example, navigate to the directory and run the main.go file:

cd examples/single_client
go run main.go

Here is the code from examples/single_client/main.go showing the default JSON-RPC usage:

package main

import (
	"log"
	"time"

	"github.com/wongpinter/godoo"
)

type Unit struct {
	Name *godoo.String `xmlrpc:"name"`
}

func main() {
	// Create a new connection pool.
	pool := godoo.NewPool(10, 5, 1*time.Minute)

	// Create a new client (JSON-RPC is used by default).
	c, err := godoo.NewClient(&godoo.ClientConfig{
		Database: "your-database",
		Admin:    "admin",
		Password: "your-password",
		URL:      "https://your-odoo-instance.com",
		Pool:     pool,
		// Protocol: godoo.ProtocolJSONRPC // This is now the default
	})
	if err != nil {
		log.Fatalf("Error creating client: %v", err)
	}
	defer c.Close()

	// Get the Odoo version.
	v, err := c.Version()
	if err != nil {
		log.Fatalf("Error getting version: %v", err)
	}
	log.Printf("Odoo version: %s", v.ServerVersion)

	// Read data from a model.
	var units []Unit
	err = c.Read("propertek.property.unit", []int64{1}, nil, &units)
	if err != nil {
		log.Fatalf("Error getting units: %v", err)
	}

	log.Printf("Units: %+v", units)
}
Protocol Selection

You can choose between JSON-RPC (default) and XML-RPC by setting the Protocol field in ClientConfig:

// JSON-RPC (default)
cfg := &godoo.ClientConfig{
    Database: "your-database",
    Admin:    "admin",
    Password: "your-password",
    URL:      "https://your-odoo-instance.com",
    Pool:     pool,
    // Protocol: godoo.ProtocolJSONRPC // This is the default, can be omitted
}

// XML-RPC (for legacy Odoo versions)
cfg := &godoo.ClientConfig{
    Database: "your-database",
    Admin:    "admin",
    Password: "your-password",
    URL:      "https://your-odoo-instance.com",
    Pool:     pool,
    Protocol: godoo.ProtocolXMLRPC,
}
XML-RPC Client Example

If you need to use XML-RPC for legacy Odoo versions, you can explicitly specify it:

// Create a new XML-RPC client.
c, err := godoo.NewClient(&godoo.ClientConfig{
    Database: "your-database",
    Admin:    "admin",
    Password: "your-password",
    URL:      "https://your-odoo-instance.com",
    Pool:     pool,
    Protocol: godoo.ProtocolXMLRPC, // Explicitly use XML-RPC
})
RPC Pool Example

To run the RPC pool example, navigate to the directory and run the main.go file:

cd examples/rpc_pool
go run main.go

This example demonstrates how to manage connections to multiple Odoo instances. See the code in examples/rpc_pool/main.go for details.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue if you find a bug or have a feature request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

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

Bool is a bool wrapper

func NewBool

func NewBool(v bool) *Bool

NewBool creates a new *Bool.

func (*Bool) Get

func (b *Bool) Get() bool

Get *Bool value.

type Client

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

Client provides high and low level functions to interact with odoo

func NewClient

func NewClient(cfg *ClientConfig) (*Client, error)

NewClient creates a new *Client.

func (*Client) Close

func (c *Client) Close()

Close closes all opened client connections.

func (*Client) Config

func (c *Client) Config() *ClientConfig

func (*Client) Count

func (c *Client) Count(model string, criteria *Criteria, options *Options) (int64, error)

Count model records matching with *Criteria. https://www.odoo.com/documentation/13.0/webservices/odoo.html#count-records

func (*Client) Create

func (c *Client) Create(model string, values interface{}) (int64, error)

Create a new model. https://www.odoo.com/documentation/13.0/webservices/odoo.html#create-records

func (*Client) Delete

func (c *Client) Delete(model string, ids []int64) error

Delete existing model row(s). https://www.odoo.com/documentation/13.0/webservices/odoo.html#delete-records

func (*Client) ExecuteKw

func (c *Client) ExecuteKw(method, model string, args []interface{}, options *Options) (interface{}, error)

ExecuteKw is a RPC function. The lowest library function. It is use for all function related to object endpoints.

func (*Client) ExecuteKwByte

func (c *Client) ExecuteKwByte(method, model string, args []interface{}, options *Options) ([]byte, error)

func (*Client) FieldsGet

func (c *Client) FieldsGet(model string, options *Options) (map[string]interface{}, error)

FieldsGet inspect model fields. https://www.odoo.com/documentation/13.0/webservices/odoo.html#listing-record-fields

func (*Client) GetProtocol

func (c *Client) GetProtocol() ProtocolType

GetProtocol returns the current protocol being used

func (*Client) IsJSONRPC

func (c *Client) IsJSONRPC() bool

IsJSONRPC returns true if the client is using JSON-RPC protocol

func (*Client) IsXMLRPC

func (c *Client) IsXMLRPC() bool

IsXMLRPC returns true if the client is using XML-RPC protocol

func (*Client) Ping

func (c *Client) Ping() error

func (*Client) Read

func (c *Client) Read(model string, ids []int64, options *Options, elem interface{}) error

Read model records matching with ids. https://www.odoo.com/documentation/13.0/webservices/odoo.html#read-records

func (*Client) Search

func (c *Client) Search(model string, criteria *Criteria, options *Options) ([]int64, error)

Search model record ids matching with *Criteria. https://www.odoo.com/documentation/13.0/webservices/odoo.html#list-records

func (*Client) SearchRead

func (c *Client) SearchRead(model string, criteria *Criteria, options *Options, elem interface{}) error

SearchRead search model records matching with *Criteria and read it. https://www.odoo.com/documentation/13.0/webservices/odoo.html#search-and-read

func (*Client) Update

func (c *Client) Update(model string, ids []int64, values interface{}) error

Update existing model row(s). https://www.odoo.com/documentation/13.0/webservices/odoo.html#update-records

func (*Client) Version

func (c *Client) Version() (Version, error)

Version get informations about your odoo instance version.

type ClientConfig

type ClientConfig struct {
	Database string
	Admin    string
	Password string
	URL      string
	Pool     *Pool
	Protocol ProtocolType
}

ClientConfig is the configuration to create a new *Client by givin connection infomations.

type ConnectionPool

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

ConnectionPool manages a collection of godoo clients.

func NewConnectionPool

func NewConnectionPool(retryInterval time.Duration, maxRetries int, serverConfigs map[string]*ClientConfig) (*ConnectionPool, error)

NewConnectionPool creates and initializes a new connection pool. It attempts to connect to all servers defined in serverConfigs and retries failed connections in the background.

func (*ConnectionPool) AddClient

func (p *ConnectionPool) AddClient(key string, cfg ClientConfig) error

AddClient creates a new client and adds it to the pool.

func (*ConnectionPool) CheckConnections

func (p *ConnectionPool) CheckConnections()

CheckConnections verifies all active connections and attempts to reconnect any that have failed.

func (*ConnectionPool) Close

func (p *ConnectionPool) Close()

Close gracefully closes all client connections in the pool.

func (*ConnectionPool) GetClient

func (p *ConnectionPool) GetClient(key string) (*Client, error)

GetClient retrieves a client from the pool by its key.

func (*ConnectionPool) NumConnections

func (p *ConnectionPool) NumConnections() int

NumConnections returns the number of active connections in the pool.

func (*ConnectionPool) RemoveClient

func (p *ConnectionPool) RemoveClient(key string)

RemoveClient closes and removes a client from the pool.

type Criteria

type Criteria []*criterion

Criteria is a set of criterion, each criterion is a triple (field_name, operator, value). It allow you to search models. see documentation: https://www.odoo.com/documentation/13.0/reference/orm.html#reference-orm-domains

func NewCriteria

func NewCriteria() *Criteria

NewCriteria creates a new *Criteria.

func (*Criteria) Add

func (c *Criteria) Add(field, operator string, value interface{}) *Criteria

Add a new criterion to a *Criteria.

type Float

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

Float is a float64 wrapper

func NewFloat

func NewFloat(v float64) *Float

NewFloat creates a new *Float.

func (*Float) Get

func (f *Float) Get() float64

Get *Float value.

type Int

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

Int is an int64 wrapper

func NewInt

func NewInt(v int64) *Int

NewInt creates a new *Int.

func (*Int) Get

func (i *Int) Get() int64

Get *Int value.

type JSONRPCClient

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

JSONRPCClient handles JSON-RPC communication with Odoo

func NewJSONRPCClient

func NewJSONRPCClient(baseURL string, pool *Pool) *JSONRPCClient

NewJSONRPCClient creates a new JSON-RPC client

func (*JSONRPCClient) Authenticate

func (c *JSONRPCClient) Authenticate(db, login, password string) error

Authenticate performs JSON-RPC authentication

func (*JSONRPCClient) Call

func (c *JSONRPCClient) Call(method string, params interface{}) (*JSONRPCResponse, error)

Call makes a JSON-RPC method call

func (*JSONRPCClient) Close

func (c *JSONRPCClient) Close()

Close closes the JSON-RPC client

func (*JSONRPCClient) ExecuteKw

func (c *JSONRPCClient) ExecuteKw(db string, uid int64, password string, model string, method string, args []interface{}, kwargs map[string]interface{}) (interface{}, error)

ExecuteKw executes a method on an Odoo model

func (*JSONRPCClient) GetSessionID

func (c *JSONRPCClient) GetSessionID() string

GetSessionID returns the current session ID

func (*JSONRPCClient) GetUID

func (c *JSONRPCClient) GetUID() int64

GetUID returns the authenticated user ID

type JSONRPCError

type JSONRPCError struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

JSONRPCError represents a JSON-RPC error

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params"`
	ID      interface{} `json:"id"`
}

JSONRPCRequest represents a JSON-RPC 2.0 request

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string        `json:"jsonrpc"`
	Result  interface{}   `json:"result,omitempty"`
	Error   *JSONRPCError `json:"error,omitempty"`
	ID      interface{}   `json:"id"`
}

JSONRPCResponse represents a JSON-RPC 2.0 response

type Many2One

type Many2One struct {
	ID   int64
	Name string
}

Many2One represents odoo many2one type. https://www.odoo.com/documentation/13.0/reference/orm.html#relational-fields

func NewMany2One

func NewMany2One(id int64, name string) *Many2One

NewMany2One create a new *Many2One.

func (*Many2One) Get

func (m *Many2One) Get() int64

Get *Many2One value.

type Options

type Options map[string]interface{}

Options allow you to filter search results.

func NewOptions

func NewOptions() *Options

NewOptions creates a new *Options

func (*Options) Add

func (o *Options) Add(opt string, v interface{}) *Options

Add on option by providing option name and value.

func (*Options) AllFields

func (o *Options) AllFields(fields ...string) *Options

AllFields is useful for FieldsGet function. It represents the fields to document you want odoo to return. https://www.odoo.com/documentation/13.0/reference/orm.html#fields-views

func (*Options) Attributes

func (o *Options) Attributes(attributes ...string) *Options

Attributes is useful for FieldsGet function. It represents the attributes to document you want odoo to return. https://www.odoo.com/documentation/13.0/reference/orm.html#fields-views

func (*Options) FetchFields

func (o *Options) FetchFields(fields ...string) *Options

FetchFields allow you to precise the model fields you want odoo to return. https://www.odoo.com/documentation/13.0/webservices/odoo.html#search-and-read

func (*Options) Limit

func (o *Options) Limit(limit int) *Options

Limit adds the limit options. https://www.odoo.com/documentation/13.0/webservices/odoo.html#pagination

func (*Options) Offset

func (o *Options) Offset(offset int) *Options

Offset adds the offset options. https://www.odoo.com/documentation/13.0/webservices/odoo.html#pagination

type Pool

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

func NewPool

func NewPool(maximalIdle, maxHosts int, idleTimeout time.Duration) *Pool

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) CloseExpired

func (p *Pool) CloseExpired()

func (*Pool) Get

func (p *Pool) Get(ctx context.Context, host string) (net.Conn, error)

func (*Pool) Put

func (p *Pool) Put(host string, conn net.Conn)

type ProtocolType

type ProtocolType string

ProtocolType defines the RPC protocol type

const (
	ProtocolXMLRPC  ProtocolType = "xmlrpc"
	ProtocolJSONRPC ProtocolType = "jsonrpc"
)

type Relation

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

Relation represents odoo one2many and many2many types. https://www.odoo.com/documentation/13.0/reference/orm.html#relational-fields

func NewRelation

func NewRelation() *Relation

NewRelation creates a new *Relation.

func (*Relation) AddNewRecord

func (r *Relation) AddNewRecord(values interface{})

AddNewRecord is an helper to create a new record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) AddRecord

func (r *Relation) AddRecord(record int64)

AddRecord is an helper to add an existing record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) DeleteRecord

func (r *Relation) DeleteRecord(record int64)

DeleteRecord is an helper to delete an existing record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) Get

func (r *Relation) Get() []int64

Get *Relation value.

func (*Relation) RemoveAllRecords

func (r *Relation) RemoveAllRecords()

RemoveAllRecords is an helper to remove all records of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) RemoveRecord

func (r *Relation) RemoveRecord(record int64)

RemoveRecord is an helper to remove an existing record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) ReplaceAllRecords

func (r *Relation) ReplaceAllRecords(newRecords []int64)

ReplaceAllRecords is an helper to replace all records of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

func (*Relation) UpdateRecord

func (r *Relation) UpdateRecord(record int64, values interface{})

UpdateRecord is an helper to update an existing record of one2many or many2many. https://www.odoo.com/documentation/13.0/reference/orm.html#odoo.models.Model.write

type Selection

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

Selection represents selection odoo type.

func NewSelection

func NewSelection(v interface{}) *Selection

NewSelection creates a new *Selection.

func (*Selection) Get

func (s *Selection) Get() interface{}

Get *Selection value.

type String

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

String is a string wrapper

func NewString

func NewString(v string) *String

NewString creates a new *String.

func (*String) Get

func (s *String) Get() string

Get *String value.

type Time

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

Time is a time.Time wrapper.

func NewTime

func NewTime(v time.Time) *Time

NewTime creates a new *Time.

func (*Time) Get

func (t *Time) Get() time.Time

Get *Time value.

type Version

type Version struct {
	ServerVersion     *String     `xmlrpc:"server_version"`
	ServerVersionInfo interface{} `xmlrpc:"server_version_info"`
	ServerSerie       *String     `xmlrpc:"server_serie"`
	ProtocolVersion   *Int        `xmlrpc:"protocol_version"`
}

Version describes odoo instance version.

Directories

Path Synopsis
examples
jsonrpc_client command
rpc_pool command
single_client command

Jump to

Keyboard shortcuts

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