Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code refactor and Test cases #12

Merged
merged 11 commits into from
May 7, 2024
7 changes: 6 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@ BASEURL_DISCOVERY="https://<base_url>/v2" # Space and Time Discovery API Endpoi
USERID="" # UserID required for authentication and authorization
JOINCODE="" # Space and Time Join Code which can be got from the SxT release team
SCHEME="ed25519" # The key scheme or algorithm required for key generation
PREFIX="" # Optional Prefix Parameter for signature generation
PREFIX="" # Optional Prefix Parameter for signature generation

henrydaly marked this conversation as resolved.
Show resolved Hide resolved
# TEST
TEST_USER=
TEST_USER_PRIVKEY=
TEST_USER_PUBKEY=
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# go-sxt-sdk (v.0.0.7)
# go-sxt-sdk (v.0.0.8)

Golang SDK for Space and Time Gateway (go version >= 1.18)

Expand Down Expand Up @@ -87,7 +87,7 @@ The generated `AccessToken` is valid for 25 minutes and the `refreshToken` for 3
```go
// New Authentication.
// Generates new accessToken, refreshToken, privateKey, and publicKey
func authenticate()(accessToken, refreshToken string, privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey){
func Authenticate()(accessToken, refreshToken string, privateKey ed25519.PrivateKey, publicKey ed25519.PublicKey){

// Read userId, joinCode from .env file
userId, _ := helpers.ReadUserId()
Expand Down
86 changes: 38 additions & 48 deletions helpers/readenvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,91 +3,81 @@ package helpers
import (
"log"
"os"
"path/filepath"

"github.com/joho/godotenv"
)

// Read User Id from Environment
func ReadUserId() (value string, ok bool){
err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}

value, ok = os.LookupEnv("USERID")

if !ok {
log.Fatal("USERID not set in environment")
envFile, _ := godotenv.Read(".env")
value = envFile["USERID"]

if value == ""{
log.Fatal("USERID not set in environment")
}
}
return value, ok

return value, true
}

// Read Join Code from Environment
func ReadJoinCode() (value string, ok bool){

err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}


value, ok = os.LookupEnv("JOINCODE")

if !ok {
log.Fatal("JOINCODE not set in environment")
}
envFile, _ := godotenv.Read(".env")
value = envFile["JOINCODE"]

return value, ok
if value == ""{
log.Fatal("JOINCODE not set in environment")
}
}

return value, true
}

// Read API End Point Discovery from Environment
func ReadEndPointDiscovery() (value string, ok bool){

err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}


value, ok = os.LookupEnv("BASEURL_DISCOVERY")

if !ok {
log.Fatal("Discovery BASEURL not set in environment")
envFile, _ := godotenv.Read(".env")
value = envFile["BASEURL_DISCOVERY"]

if value == ""{
log.Fatal("BASEURL_DISCOVERY not set in environment")
}
}
return value, ok
return value, true
}

// Read API End Point Others in General from Environment
func ReadEndPointGeneral() (value string, ok bool){

err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}


value, ok = os.LookupEnv("BASEURL_GENERAL")

if !ok {
log.Fatal("General BASEURL not set in environment")
envFile, _ := godotenv.Read(".env")
value = envFile["BASEURL_GENERAL"]

if value == ""{
log.Fatal("BASEURL_GENERAL not set in environment")
}
}
return value, ok

return value, true
}

// Read Scheme from Environment
func ReadScheme() (value string, ok bool){

err := godotenv.Load(filepath.Join("./", ".env"))
if err != nil {
log.Fatal(err.Error())
}


value, ok = os.LookupEnv("SCHEME")

if !ok {
log.Fatal("SCHEME not set in environment")
envFile, _ := godotenv.Read(".env")
value = envFile["SCHEME"]

if value == ""{
log.Fatal("SCHEME not set in environment")
}
}
return value, ok
return value, true
}
Loading
Loading