diff --git a/app/auth0.go b/app/auth0.go index 6169701..cac5f08 100644 --- a/app/auth0.go +++ b/app/auth0.go @@ -14,7 +14,7 @@ type auth0TokenResponse struct { TokenType string } -const tokenURL = "https://taxnexus.auth0.com/oauth/token" +const tokenURL = "https://taxnexus.auth0.com/oauth/token" //nolint:gosec // false positive const tokenTimeout = 86400 * time.Second const requestTemplate = ` { diff --git a/app/meta.go b/app/meta.go new file mode 100644 index 0000000..e591c44 --- /dev/null +++ b/app/meta.go @@ -0,0 +1,77 @@ +package app + +import ( + "fmt" + "time" +) + +// InjectResponseMeta takes a ResopnseMeta instance and injects additional metadata +func InjectResponseMeta(r *ResponseMeta) *ResponseMeta { + theResponseMeta := ResponseMeta{ + Contact: "Contact Taxnexus at https://taxnexus.net/, info@taxnexus.net or +1-510-679-1900", + Copyright: "Taxnexus API and all Taxnexus content is Copyright (c) 2018-2020 by Taxnexus, Inc. All Rights Reserved.", //nolint:lll // response text + License: "Proprietary - Do Not Copy", + Pagination: r.Pagination, + TaxnexusAccount: r.TaxnexusAccount, + ServerInfo: r.ServerInfo, + ServerResponseTime: r.ServerResponseTime, + ServerTimestamp: r.ServerTimestamp, + RequestType: r.RequestType, + RequestIP: r.RequestIP, + RequestURL: r.RequestURL, + } + return &theResponseMeta +} + +// NewResponseMeta creates a template meta response +func NewResponseMeta() *ResponseMeta { + return &ResponseMeta{ + Contact: "Contact Taxnexus at https://taxnexus.net/, info@taxnexus.net or +1-510-679-1900", + Copyright: "Taxnexus API and all Taxnexus content is Copyright (c) 2018-2020 by Taxnexus, Inc. All Rights Reserved.", //nolint:lll // response text + License: "Proprietary - Do Not Copy", + Pagination: &Pagination{ + Limit: 1, + Pagesize: 1, + Poffset: 0, + Setsize: 1, + }, + ServerInfo: "Taxnexus v1.2.7 - Go", + ServerTimestamp: fmt.Sprint(time.Now().Local()), + } +} + +// NewResponseMetaWithPagination creates a template meta response with pagination +func NewResponseMetaWithPagination(p *Pagination) *ResponseMeta { + return &ResponseMeta{ + Contact: "Contact Taxnexus at https://taxnexus.net/, info@taxnexus.net or +1-510-679-1900", + Copyright: "Taxnexus API and all Taxnexus content is Copyright (c) 2018-2020 by Taxnexus, Inc. All Rights Reserved.", //nolint:lll // response text + License: "Proprietary - Do Not Copy", + ServerInfo: "Taxnexus v1.2.7 - Go", + ServerTimestamp: fmt.Sprint(time.Now()), + Pagination: p, + } +} + +// ResponseMeta is a struct +type ResponseMeta struct { + Contact string + Copyright string + License string + OperationID string + Pagination *Pagination + RequestIP string + RequestType string + RequestURL string + ServerInfo string + ServerResponseTime string + ServerTimestamp string + TaxnexusAccount string +} + +// Pagination is a struct +type Pagination struct { + Limit int64 + Pagesize int64 + Poffset int64 + Setsize int64 +} diff --git a/app/mysql.go b/app/mysql.go new file mode 100644 index 0000000..82227f2 --- /dev/null +++ b/app/mysql.go @@ -0,0 +1,26 @@ +package app + +import ( + "database/sql" +) + +// MyDB is the MySQL handler variable +var MyDB *sql.DB + +// InitDB initializes the MySQL database using DSN information from the config file +func InitDB() { + var db *sql.DB + var err error + if GetDBMS() == "mysql" { + db, err = sql.Open("mysql", GetDSN()) + } else { + sugar.Fatalf("app.InitDB: 💣 ⛔ unknown DBMS: %s", GetDBMS()) + return + } + if err != nil { + sugar.Fatalf("app.InitDB: 💣 ⛔ Can't log on to DBMS host: %w", err) + return + } + MyDB = db + sugar.Debugf("app.InitDB: 👍 📤 %s", GetDBMS()) +}