Documentation ¶
Overview ¶
Package gobl contains all the base models for GOBL.
Index ¶
- Variables
- func Parse(data []byte) (interface{}, error)
- type Envelope
- func (e *Envelope) Calculate() error
- func (e *Envelope) Correct(opts ...schema.Option) (*Envelope, error)
- func (e *Envelope) CorrectionOptionsSchema() (interface{}, error)
- func (e *Envelope) Digest() (*dsig.Digest, error)
- func (e *Envelope) Extract() interface{}
- func (e *Envelope) Insert(doc interface{}) error
- func (e *Envelope) Sign(key *dsig.PrivateKey) error
- func (e *Envelope) Validate() error
- func (e *Envelope) ValidateWithContext(ctx context.Context) error
- type Error
- type Version
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoDocument is provided when the envelope does not contain a // document payload. ErrNoDocument = NewError("no-document") // ErrValidation is used when a document fails a validation request. ErrValidation = NewError("validation") // ErrCalculation wraps around errors that we're generated during a // call to perform calculations on a document. ErrCalculation = NewError("calculation") // ErrMarshal is provided when there has been a problem attempting to encode // or marshal an object, usually into JSON. ErrMarshal = NewError("marshal") // ErrUnmarshal is used when that has been a problem attempting to read the // source data. ErrUnmarshal = NewError("unmarshal") // ErrSignature identifies an issue related to signatures. ErrSignature = NewError("signature") // ErrInternal is a "catch-all" for errors that are not expected. ErrInternal = NewError("internal") // ErrUnknownSchema is provided when we attempt to determine the schema for an object // or from an ID and cannot find a match. ErrUnknownSchema = NewError("unknown-schema") )
var EnvelopeSchema = schema.GOBL.Add("envelope")
EnvelopeSchema sets the general definition of the schema ID for this version of the envelope.
Functions ¶
Types ¶
type Envelope ¶
type Envelope struct { // Schema identifies the schema that should be used to understand this document Schema schema.ID `json:"$schema" jsonschema:"title=JSON Schema ID"` // Details on what the contents are Head *head.Header `json:"head" jsonschema:"title=Header"` // The data inside the envelope Document *schema.Object `json:"doc" jsonschema:"title=Document"` // JSON Web Signatures of the header Signatures []*dsig.Signature `json:"sigs,omitempty" jsonschema:"title=Signatures"` }
Envelope wraps around a document adding headers and digital signatures. An Envelope is similar to a regular envelope in the physical world, it keeps the contents safe and helps get the document where its needed.
func Envelop ¶ added in v0.20.0
Envelop is a convenience method that will build a new envelope and insert the contents document provided in a single swoop. The resulting envelope will still need to be signed afterwards.
func NewEnvelope ¶
func NewEnvelope() *Envelope
NewEnvelope builds a new envelope object ready for data to be inserted and signed. If you are loading data from json, you can safely use a regular `new(Envelope)` call directly.
Example (Complete) ¶
package main import ( "encoding/json" "fmt" "github.com/invopop/gobl" "github.com/invopop/gobl/note" "github.com/invopop/gobl/uuid" ) func main() { // Prepare a new Envelope with a region env := gobl.NewEnvelope() env.Head.UUID = uuid.MustParse("871c1e6a-8b5c-11ec-af5f-3e7e00ce5635") // Prepare a payload and insert msg := ¬e.Message{ Content: "sample message content", } if err := env.Insert(msg); err != nil { panic(err.Error()) } if err := env.Validate(); err != nil { panic(err.Error()) } data, err := json.MarshalIndent(env, "", "\t") if err != nil { panic(err.Error()) } fmt.Printf("%v\n", string(data)) }
Output: { "$schema": "https://gobl.org/draft-0/envelope", "head": { "uuid": "871c1e6a-8b5c-11ec-af5f-3e7e00ce5635", "dig": { "alg": "sha256", "val": "7d539c46ca03a4ecb1fcc4cb00d2ada34275708ee326caafee04d9dcfed862ee" }, "draft": true }, "doc": { "$schema": "https://gobl.org/draft-0/note/message", "content": "sample message content" } }
func (*Envelope) Calculate ¶ added in v0.28.0
Calculate is used to perform calculations on the envelope's document contents to ensure everything looks correct. Headers will be refreshed to ensure they have the latest valid digest.
func (*Envelope) Correct ¶ added in v0.40.0
Correct will attempt to build a new envelope as a correction of the current envelope contents, if possible.
func (*Envelope) CorrectionOptionsSchema ¶ added in v0.58.1
CorrectionOptionsSchema will attempt to provide a corrective options JSON Schema that can be used to generate a JSON object to send when correcting a document. If none are available, the result will be nil.
func (*Envelope) Digest ¶ added in v0.56.0
Digest calculates a digital digest using the canonical JSON of the document.
func (*Envelope) Extract ¶
func (e *Envelope) Extract() interface{}
Extract the contents of the envelope into the provided document type.
func (*Envelope) Insert ¶
Insert takes the provided document and inserts it into this envelope. Calculate will be called automatically.
func (*Envelope) Sign ¶
func (e *Envelope) Sign(key *dsig.PrivateKey) error
Sign uses the private key to sign the envelope headers. The header draft flag will be set to false and validation is performed so that only valid non-draft documents will be signed.
type Error ¶
Error provides a structure to better be able to make error comparisons. The contents can also be serialised as JSON ready to send to a client if needed.
func (*Error) Is ¶
Is checks to see if the target error matches the current error or part of the chain.
func (*Error) WithErrorf ¶
WithErrorf wraps around the `fmt.Errorf` call to provide a more meaningful error in the context.
func (*Error) WithReason ¶ added in v0.56.0
WithReason returns an error with a reason attached.
Directories ¶
Path | Synopsis |
---|---|
Package bill provides models for dealing with Billing and specifically invoicing.
|
Package bill provides models for dealing with Billing and specifically invoicing. |
Package c14n provides canonical JSON encoding and decoding.
|
Package c14n provides canonical JSON encoding and decoding. |
Package cal provides simple date handling.
|
Package cal provides simple date handling. |
Package cbc provides a set of Common Basic Components.
|
Package cbc provides a set of Common Basic Components. |
Package currency provides models for dealing with currencies.
|
Package currency provides models for dealing with currencies. |
Package data contains both generated and embedded data.
|
Package data contains both generated and embedded data. |
Package dsig provides models for dealing with digital signatures.
|
Package dsig provides models for dealing with digital signatures. |
examples
|
|
Package head defines the contents to be used in envelope headers.
|
Package head defines the contents to be used in envelope headers. |
Package i18n provides internationalization models.
|
Package i18n provides internationalization models. |
Package internal contains internal objects that may be used for reference inside GOBL but are not intended for use outside of the library.
|
Package internal contains internal objects that may be used for reference inside GOBL but are not intended for use outside of the library. |
currency
Package currency is used internally to generate Go currency structures from a data source.
|
Package currency is used internally to generate Go currency structures from a data source. |
iotools
Package iotools helps with reading documents.
|
Package iotools helps with reading documents. |
schemas
Package schemas helps generate JSON Schema files from the main GOBL packages.
|
Package schemas helps generate JSON Schema files from the main GOBL packages. |
Package l10n provides localization models and data.
|
Package l10n provides localization models and data. |
Package note provides models for generating simple messages.
|
Package note provides models for generating simple messages. |
Package num provides support for dealing with amounts and percentages without rounding errors.
|
Package num provides support for dealing with amounts and percentages without rounding errors. |
Package org contains structures related to organization.
|
Package org contains structures related to organization. |
Package pay handles models related to payments.
|
Package pay handles models related to payments. |
pkg
|
|
here
Package here provides creation of here-documents from raw strings.
|
Package here provides creation of here-documents from raw strings. |
Package regimes simple ensures that each of the individually defined tax regimes is loaded correctly and ready to use from other GOBL packages.
|
Package regimes simple ensures that each of the individually defined tax regimes is loaded correctly and ready to use from other GOBL packages. |
ca
Package ca provides models for dealing with Canada.
|
Package ca provides models for dealing with Canada. |
co
Package co handles tax regime data for Colombia.
|
Package co handles tax regime data for Colombia. |
common
Package common provides re-usable regime related structures and data.
|
Package common provides re-usable regime related structures and data. |
de
Package de provides the tax region definition for Germany.
|
Package de provides the tax region definition for Germany. |
es
Package es provides tax regime support for Spain.
|
Package es provides tax regime support for Spain. |
fr
Package fr provides the tax region definition for France.
|
Package fr provides the tax region definition for France. |
gb
Package gb provides the United Kingdom tax regime.
|
Package gb provides the United Kingdom tax regime. |
it
Package it provides the Italian tax regime.
|
Package it provides the Italian tax regime. |
mx
Package mx provides the Mexican tax regime.
|
Package mx provides the Mexican tax regime. |
nl
Package nl provides the Dutch region definition
|
Package nl provides the Dutch region definition |
pl
Package pl provides the Polish tax regime.
|
Package pl provides the Polish tax regime. |
pt
Package pt provides models for dealing with the Portuguese tax regime.
|
Package pt provides models for dealing with the Portuguese tax regime. |
us
Package us provides models for dealing with the United States of America.
|
Package us provides models for dealing with the United States of America. |
Package schema provides a simple way to register and lookup schemas.
|
Package schema provides a simple way to register and lookup schemas. |
Package tax encapsulates models related to taxation.
|
Package tax encapsulates models related to taxation. |
Package uuid provides a wrapper for handling UUID codes.
|
Package uuid provides a wrapper for handling UUID codes. |