From 198fd10bf0e2e47dcf3edcdd6b0117d28356ff5d Mon Sep 17 00:00:00 2001 From: Asara Date: Sat, 18 Jan 2020 21:46:46 -0500 Subject: [PATCH] go fmt, add some basic tests for postal api info --- main.go | 3 +++ packages/auth/auth.go | 18 ++++++++++++++++-- packages/blog/blog.go | 1 - settings/secrets.env-sample | 2 +- settings/website.env-sample | 1 + 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 6b89624..5feb79e 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,9 @@ func main() { users.TokenAuth = auth.TokenAuth blog.TokenAuth = auth.TokenAuth + // initilize auth + auth.Init() + // initiate the routes router := Routes() diff --git a/packages/auth/auth.go b/packages/auth/auth.go index fe02414..8ea5a20 100644 --- a/packages/auth/auth.go +++ b/packages/auth/auth.go @@ -13,15 +13,29 @@ import ( "github.com/go-chi/render" "golang.org/x/crypto/bcrypt" "net/http" + "os" "strings" "time" ) var ( - DB *sql.DB - TokenAuth *jwtauth.JWTAuth + DB *sql.DB + TokenAuth *jwtauth.JWTAuth + PostalEnabled bool + PostalKey string + PostalAPI string ) +func Init() { + if postal_key, ok := os.LookupEnv("POSTAL_KEY"); ok { + PostalKey = postal_key + if postal_api, ok := os.LookupEnv("POSTAL_API"); ok { + PostalAPI = postal_api + PostalEnabled = true + } + } +} + type ReturnError struct { Message string `json:"error"` } diff --git a/packages/blog/blog.go b/packages/blog/blog.go index 2c1d630..88c4f72 100644 --- a/packages/blog/blog.go +++ b/packages/blog/blog.go @@ -57,7 +57,6 @@ type ReferenceID struct { LastID int `json:"last_id"` } - func Routes() *chi.Mux { r := chi.NewRouter() r.Group(func(r chi.Router) { diff --git a/settings/secrets.env-sample b/settings/secrets.env-sample index e21400a..a2f66a9 100644 --- a/settings/secrets.env-sample +++ b/settings/secrets.env-sample @@ -1,2 +1,2 @@ export DB_PW="CHANGEME" -export POSTAL_API="POSTAL_API_KEY" +export POSTAL_KEY="POSTAL_API_KEY" diff --git a/settings/website.env-sample b/settings/website.env-sample index 26a28d8..c638859 100644 --- a/settings/website.env-sample +++ b/settings/website.env-sample @@ -1,2 +1,3 @@ export API_PORT="8080" export JWT_SECRET="CHANGEMEALSO" +export POSTAL_API="https://POSTAL_URL"