Skip to content

Commit

Permalink
Load env from the directory
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanBudimir committed Aug 27, 2020
1 parent 26394d6 commit 78d8218
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Handle/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func AccessToken(code string, w http.ResponseWriter,r *http.Request) (*Access, e
// GetData function returns users details (TBD)
func GetData(accessToken string, w http.ResponseWriter, r *http.Request) (*User, error) {

ctx := context.Background()
client := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{
client := oauth2.NewClient(context.Background(), oauth2.StaticTokenSource(&oauth2.Token{
AccessToken: accessToken,
TokenType: "Bearer",
}))
Expand Down
2 changes: 1 addition & 1 deletion Handle/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func Env(w http.ResponseWriter, r *http.Request) {

} else if r.Method == "GET" {

form := Layout.Generate("", "<form method=\"POST\" action=\"\">" +
form := layout.Generate("", "<form method=\"POST\" action=\"\">" +
"<center>" +
"<div><label>Please enter client id</label><input class=\"form-control w-50 m-2\" type=\"number\" name=\"client_id\" placeholder=\"Please enter client id\"></div>" +
"</center>" +
Expand Down
23 changes: 22 additions & 1 deletion Helpers/check.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,33 @@
package helpers

import (
"log"
"os"
"github.com/joho/godotenv"
)

var (
client_id, redirect, secret, scopes, connection string
)

// load function loads the environmental variables
func load() {
if err := godotenv.Load("./.env"); err != nil {
log.Fatal(err)
}

client_id = os.Getenv("CLIENT_ID")
redirect = os.Getenv("REDIRECT")
scopes = os.Getenv("SCOPES")
secret = os.Getenv("SECRET")
connection = os.Getenv("CONNECTION")

}

// CheckData function checks are any of these environmental variables empty
func CheckData() (r bool) {
if os.Getenv("client_id") == "" || os.Getenv("redirect") == "" || os.Getenv("secret") == "" || os.Getenv("scopes") == "" || os.Getenv("connection") == "" {
load()
if client_id == "" || redirect == "" || secret == "" || scopes == "" || connection == "" {
return false
}
return true
Expand Down
5 changes: 5 additions & 0 deletions examples/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CLIENT_ID=
REDIRECT=
SCOPES=
SECRET=
CONNECTION=
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.15
require (
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab
github.com/joho/godotenv v1.3.0 // indirect
github.com/vatsimnetwork/connect-go v0.0.0-20200609160753-ca8779ee3fc5
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab h1:xveKWz2iauee
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/vatsimnetwork/connect-go v0.0.0-20200609160753-ca8779ee3fc5 h1:Rpm7hdyoLbwOsBY832imp/QFlWMQGp4Yzz5y96Ql8Pw=
github.com/vatsimnetwork/connect-go v0.0.0-20200609160753-ca8779ee3fc5/go.mod h1:GYpi0z68ZWnVVF0snFOdHD5D1sJVLz3YKaNrugRH4C8=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down

0 comments on commit 78d8218

Please sign in to comment.