Skip to content

Commit

Permalink
Merge pull request #3 from printesoi/standard-go-project-layout
Browse files Browse the repository at this point in the history
Use Standard Go Project Layout
  • Loading branch information
printesoi authored Oct 19, 2024
2 parents fc4fd7f + 083bc4a commit dd6a9b5
Show file tree
Hide file tree
Showing 44 changed files with 58 additions and 57 deletions.
2 changes: 1 addition & 1 deletion cmd/efactura-cli/cmd/api_get_messages_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

"github.com/printesoi/e-factura-go/efactura"
"github.com/printesoi/e-factura-go/pkg/efactura"
"github.com/spf13/cobra"
)

Expand Down
5 changes: 3 additions & 2 deletions cmd/efactura-cli/cmd/api_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"bytes"
"context"
"fmt"
"github.com/printesoi/e-factura-go/efactura"
"github.com/spf13/cobra"
"os"

"github.com/printesoi/e-factura-go/pkg/efactura"
"github.com/spf13/cobra"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion cmd/efactura-cli/cmd/api_xml2pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"os"

"github.com/printesoi/e-factura-go/efactura"
"github.com/printesoi/e-factura-go/pkg/efactura"
"github.com/spf13/cobra"
)

Expand Down
8 changes: 4 additions & 4 deletions cmd/efactura-cli/cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (

"github.com/spf13/cobra"

efacturaclient "github.com/printesoi/e-factura-go/client"
"github.com/printesoi/e-factura-go/constants"
"github.com/printesoi/e-factura-go/efactura"
"github.com/printesoi/e-factura-go/oauth2"
efacturaclient "github.com/printesoi/e-factura-go/pkg/client"
"github.com/printesoi/e-factura-go/pkg/constants"
"github.com/printesoi/e-factura-go/pkg/efactura"
"github.com/printesoi/e-factura-go/pkg/oauth2"
)

func newOAuth2Config(cmd *cobra.Command) (cfg oauth2.Config, err error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/efactura-cli/cmd/public_api_validate_xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"os"

"github.com/printesoi/e-factura-go/efactura"
"github.com/printesoi/e-factura-go/pkg/efactura"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/efactura-cli/cmd/public_api_xml2pdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"
"os"

"github.com/printesoi/e-factura-go/efactura"
"github.com/printesoi/e-factura-go/pkg/efactura"
"github.com/spf13/cobra"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/etransport-cli/cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/spf13/cobra"

"github.com/printesoi/e-factura-go/etransport"
"github.com/printesoi/e-factura-go/oauth2"
"github.com/printesoi/e-factura-go/pkg/etransport"
"github.com/printesoi/e-factura-go/pkg/oauth2"
)

func newOAuth2Config(cmd *cobra.Command) (cfg oauth2.Config, err error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"regexp"
"strconv"

errors "github.com/printesoi/e-factura-go/errors"
api_helpers "github.com/printesoi/e-factura-go/internal/helpers/api"
"github.com/printesoi/e-factura-go/internal/ptr"
iregexp "github.com/printesoi/e-factura-go/internal/regexp"
errors "github.com/printesoi/e-factura-go/pkg/errors"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions client/client.go → pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (

xoauth2 "golang.org/x/oauth2"

"github.com/printesoi/e-factura-go/constants"
ierrors "github.com/printesoi/e-factura-go/internal/errors"
api_helpers "github.com/printesoi/e-factura-go/internal/helpers/api"
"github.com/printesoi/e-factura-go/xml"
"github.com/printesoi/e-factura-go/pkg/constants"
"github.com/printesoi/e-factura-go/pkg/xml"
)

const (
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions client/client_test.go → pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"testing"
"time"

"github.com/printesoi/e-factura-go/constants"
api_helpers "github.com/printesoi/e-factura-go/internal/helpers/api"
"github.com/printesoi/e-factura-go/oauth2"
"github.com/printesoi/e-factura-go/pkg/constants"
"github.com/printesoi/e-factura-go/pkg/oauth2"
"github.com/stretchr/testify/assert"
xoauth2 "golang.org/x/oauth2"
)
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion client/revoke.go → pkg/client/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"net/http"
"net/url"

"github.com/printesoi/e-factura-go/oauth2"
"github.com/printesoi/e-factura-go/pkg/oauth2"
)

func (c *ApiClient) RevokeAccessToken(ctx context.Context, accessToken string) error {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion efactura/builders.go → pkg/efactura/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package efactura
import (
ierrors "github.com/printesoi/e-factura-go/internal/errors"
"github.com/printesoi/e-factura-go/internal/ptr"
"github.com/printesoi/e-factura-go/types"
"github.com/printesoi/e-factura-go/pkg/types"
)

// InvoiceLineAllowanceChargeBuilder builds an InvoiceLineAllowanceCharge object
Expand Down
4 changes: 2 additions & 2 deletions efactura/builders_test.go → pkg/efactura/builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (

"github.com/stretchr/testify/assert"

"github.com/printesoi/e-factura-go/text"
"github.com/printesoi/e-factura-go/types"
"github.com/printesoi/e-factura-go/pkg/text"
"github.com/printesoi/e-factura-go/pkg/types"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions efactura/client.go → pkg/efactura/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (

xoauth2 "golang.org/x/oauth2"

"github.com/printesoi/e-factura-go/client"
"github.com/printesoi/e-factura-go/constants"
"github.com/printesoi/e-factura-go/pkg/client"
"github.com/printesoi/e-factura-go/pkg/constants"
)

// ClientConfig is the config used to create a Client
Expand Down
2 changes: 1 addition & 1 deletion efactura/client_test.go → pkg/efactura/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

xoauth2 "golang.org/x/oauth2"

"github.com/printesoi/e-factura-go/oauth2"
"github.com/printesoi/e-factura-go/pkg/oauth2"
)

func getTestCIF() string {
Expand Down
2 changes: 1 addition & 1 deletion efactura/codes.go → pkg/efactura/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package efactura
import (
"strings"

"github.com/printesoi/e-factura-go/text"
"github.com/printesoi/e-factura-go/pkg/text"
)

// https://unece.org/fileadmin/DAM/trade/untdid/d16b/tred/tred1001.htm
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions efactura/invoice.go → pkg/efactura/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package efactura
import (
"fmt"

"github.com/printesoi/e-factura-go/types"
ixml "github.com/printesoi/e-factura-go/xml"
"github.com/printesoi/e-factura-go/pkg/types"
pxml "github.com/printesoi/e-factura-go/pkg/xml"
"github.com/printesoi/xml-go"
)

Expand Down Expand Up @@ -198,9 +198,9 @@ type Invoice struct {
// Prefill sets the NS, NScac, NScbc and Comment properties for ensuring that
// the required attributes and properties are set for a valid UBL XML.
func (iv *Invoice) Prefill() {
iv.Namespace = ixml.XMLNSUBLInvoice2
iv.NamespaceCAC = ixml.XMLNSUBLcac
iv.NamespaceCBC = ixml.XMLNSUBLcbc
iv.Namespace = pxml.XMLNSUBLInvoice2
iv.NamespaceCAC = pxml.XMLNSUBLcac
iv.NamespaceCBC = pxml.XMLNSUBLcbc
iv.UBLVersionID = UBLVersionID
iv.CustomizationID = CIUSRO_v101
if iv.Comment == "" {
Expand All @@ -210,29 +210,29 @@ func (iv *Invoice) Prefill() {

func (iv Invoice) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
type invoice Invoice
ixml.SetupUBLXMLEncoder(e)
pxml.SetupUBLXMLEncoder(e)
iv.Prefill()
return e.EncodeElement(invoice(iv), start)
}

// XML returns the XML encoding of the Invoice
func (iv Invoice) XML() ([]byte, error) {
return ixml.MarshalXMLWithHeader(iv)
return pxml.MarshalXMLWithHeader(iv)
}

// XMLIndent works like XML, but each XML element begins on a new
// indented line that starts with prefix and is followed by one or more
// copies of indent according to the nesting depth.
func (iv Invoice) XMLIndent(prefix, indent string) ([]byte, error) {
return ixml.MarshalIndentXMLWithHeader(iv, prefix, indent)
return pxml.MarshalIndentXMLWithHeader(iv, prefix, indent)
}

// UnmarshalInvoice unmarshals an Invoice from XML data. Only use this method
// for unmarshaling an Invoice, since the standard encoding/xml cannot
// properly unmarshal a struct like Invoice due to namespace prefixes. This
// method does not check if the unmarshaled Invoice is valid.
func UnmarshalInvoice(xmlData []byte, invoice *Invoice) error {
return ixml.UnmarshalXML(xmlData, invoice)
return pxml.UnmarshalXML(xmlData, invoice)
}

type InvoiceBillingReference struct {
Expand Down
22 changes: 11 additions & 11 deletions efactura/rest.go → pkg/efactura/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
api_helpers "github.com/printesoi/e-factura-go/internal/helpers/api"
"github.com/printesoi/e-factura-go/internal/ptr"
iregexp "github.com/printesoi/e-factura-go/internal/regexp"
itime "github.com/printesoi/e-factura-go/time"
ixml "github.com/printesoi/e-factura-go/xml"
ptime "github.com/printesoi/e-factura-go/pkg/time"
pxml "github.com/printesoi/e-factura-go/pkg/xml"
)

type (
Expand Down Expand Up @@ -458,7 +458,7 @@ func (m Message) GetBuyerCIF() (buyerCIF string) {
// GetCreationDate parsed CreationDate and returns a time.Time in
// RoZoneLocation.
func (m Message) GetCreationDate() (time.Time, bool) {
t, err := itime.ParseInRomania(messageTimeLayout, m.CreationDate)
t, err := ptime.ParseInRomania(messageTimeLayout, m.CreationDate)
return t, err == nil
}

Expand Down Expand Up @@ -514,7 +514,7 @@ func (c *Client) ValidateXML(ctx context.Context, xml io.Reader, st ValidateStan

// ValidateInvoice validate the provided Invoice
func (c *Client) ValidateInvoice(ctx context.Context, invoice Invoice) (*ValidateResponse, error) {
xmlReader, err := ixml.MarshalXMLToReader(invoice)
xmlReader, err := pxml.MarshalXMLToReader(invoice)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -573,7 +573,7 @@ func (c *Client) XMLToPDF(ctx context.Context, xml io.Reader, st ValidateStandar
// InvoiceToPDF convert the given Invoice to PDF. See XMLToPDF for return
// values.
func (c *Client) InvoiceToPDF(ctx context.Context, invoice Invoice, noValidate bool) (response *GeneratePDFResponse, err error) {
xmlReader, err := ixml.MarshalXMLToReader(invoice)
xmlReader, err := pxml.MarshalXMLToReader(invoice)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -642,7 +642,7 @@ func (c *Client) UploadXML(
func (c *Client) UploadInvoice(
ctx context.Context, invoice Invoice, cif string, opts ...UploadOption,
) (response *UploadResponse, err error) {
xmlReader, err := ixml.MarshalXMLToReader(invoice)
xmlReader, err := pxml.MarshalXMLToReader(invoice)
if err != nil {
return nil, err
}
Expand All @@ -654,7 +654,7 @@ func (c *Client) UploadInvoice(
func (c *Client) UploadRaspMessage(
ctx context.Context, msg RaspMessage, cif string,
) (response *UploadResponse, err error) {
xmlReader, err := ixml.MarshalXMLToReader(msg)
xmlReader, err := pxml.MarshalXMLToReader(msg)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -891,20 +891,20 @@ func parseDownloadedInvoiceXML(ctx context.Context, invoiceXML []byte) (invoice
XMLName xml.Name
}
var doc docName
if err = ixml.UnmarshalXML(invoiceXML, &doc); err != nil {
if err = pxml.UnmarshalXML(invoiceXML, &doc); err != nil {
return
}
switch doc.XMLName.Space {
case ixml.XMLNSUBLInvoice2:
case pxml.XMLNSUBLInvoice2:
iv := new(Invoice)
if err = ixml.UnmarshalXML(invoiceXML, iv); err != nil {
if err = pxml.UnmarshalXML(invoiceXML, iv); err != nil {
return
}
invoice = iv

case XMLNSMsgErrorV1:
ie := new(InvoiceErrorMessage)
if err = ixml.UnmarshalXML(invoiceXML, &ie); err != nil {
if err = pxml.UnmarshalXML(invoiceXML, &ie); err != nil {
return
}
invoiceError = ie
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion efactura/xml_types.go → pkg/efactura/xml_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package efactura

import (
"github.com/printesoi/e-factura-go/types"
"github.com/printesoi/e-factura-go/pkg/types"
"github.com/printesoi/xml-go"
)

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion etransport/client.go → pkg/etransport/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

xoauth2 "golang.org/x/oauth2"

"github.com/printesoi/e-factura-go/client"
"github.com/printesoi/e-factura-go/pkg/client"
)

// ClientConfig is the config used to create a Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/stretchr/testify/assert"
xoauth2 "golang.org/x/oauth2"

"github.com/printesoi/e-factura-go/oauth2"
"github.com/printesoi/e-factura-go/pkg/oauth2"
)

func getTestCIF() string {
Expand Down
2 changes: 1 addition & 1 deletion etransport/codes.go → pkg/etransport/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package etransport
import (
"strings"

"github.com/printesoi/e-factura-go/text"
"github.com/printesoi/e-factura-go/pkg/text"
)

type DeclPostIncidentType string
Expand Down
4 changes: 2 additions & 2 deletions etransport/declaration.go → pkg/etransport/declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package etransport
import (
"errors"

"github.com/printesoi/e-factura-go/types"
ixml "github.com/printesoi/e-factura-go/xml"
"github.com/printesoi/e-factura-go/pkg/types"
ixml "github.com/printesoi/e-factura-go/pkg/xml"
"github.com/printesoi/xml-go"
)

Expand Down
4 changes: 2 additions & 2 deletions etransport/rest.go → pkg/etransport/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"strings"

ierrors "github.com/printesoi/e-factura-go/internal/errors"
"github.com/printesoi/e-factura-go/types"
ixml "github.com/printesoi/e-factura-go/xml"
"github.com/printesoi/e-factura-go/pkg/types"
ixml "github.com/printesoi/e-factura-go/pkg/xml"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion oauth2/config.go → pkg/oauth2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

"github.com/printesoi/e-factura-go/errors"
"github.com/printesoi/e-factura-go/pkg/errors"
xoauth2 "golang.org/x/oauth2"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion types/date.go → pkg/types/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/printesoi/xml-go"

itime "github.com/printesoi/e-factura-go/time"
itime "github.com/printesoi/e-factura-go/pkg/time"
)

// Date is a wrapper of the time.Time type which marshals to XML in the
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions util/conv.go → pkg/util/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
package util

import (
"github.com/printesoi/e-factura-go/efactura"
"github.com/printesoi/e-factura-go/etransport"
"github.com/printesoi/e-factura-go/pkg/efactura"
"github.com/printesoi/e-factura-go/pkg/etransport"
)

// EfacturaRoCountrySubentityToEtransportCountyCode convert the given
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit dd6a9b5

Please sign in to comment.