-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 43dfbef
Showing
8 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github: [lalabuy948] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: | ||
tags: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: set up go 1.14 | ||
uses: actions/setup-go@v1 | ||
with: | ||
go-version: 1.14 | ||
id: go | ||
|
||
- name: checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: build and test | ||
run: | | ||
export GO111MODULE=on | ||
go get -v | ||
go test -timeout=60s -v -covermode=count -coverprofile=$GITHUB_WORKSPACE/profile.cov_tmp | ||
cat $GITHUB_WORKSPACE/profile.cov_tmp | grep -v "_mock.go" > $GITHUB_WORKSPACE/profile.cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.vscode | ||
.idea | ||
|
||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Lalabuy948 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# gonvutils [![Go Report Card](https://goreportcard.com/badge/github.com/lalabuy948/gonvutils)](https://goreportcard.com/report/github.com/lalabuy948/gonvutils) [![Coverage Status](https://coveralls.io/repos/github.com/lalabuy948/gonvutils/badge.svg?branch=master)] | ||
|
||
> Package gonvutils provides useful environment operations | ||
## Funcs | ||
|
||
- `IsProduction`, `IsDevelopment` and `IsTesting` checks for `ENVIRONMENT` dot env value. | ||
- `GetEnv` gets env value, fallback as second function argument. | ||
|
||
## Install | ||
|
||
go get -u github.com/lalabuy948/gonvutils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/lalabuy948/gonvutils | ||
|
||
go 1.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Package gonvutils provides useful environment operations | ||
package gonvutils | ||
|
||
import "os" | ||
|
||
//IsProduction checks if ENVIRONMENT value is equal to "PROD". | ||
func IsProduction() bool { | ||
if os.Getenv("ENVIRONMENT") == "PROD" { | ||
return true | ||
} | ||
if os.Getenv("ENVIRONMENT") == "PRODUCTION" { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
//IsDevelopment checks if ENVIRONMENT value is equal to "DEV". | ||
func IsDevelopment() bool { | ||
if os.Getenv("ENVIRONMENT") == "DEV" { | ||
return true | ||
} | ||
if os.Getenv("ENVIRONMENT") == "DEVELOPMENT" { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
//IsTesting checks if ENVIRONMENT value is equal to "TEST". | ||
func IsTesting() bool { | ||
if os.Getenv("ENVIRONMENT") == "TEST" { | ||
return true | ||
} | ||
if os.Getenv("ENVIRONMENT") == "TESTING" { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
//GetEnv extracts env value by provided key, otherwise falls back to second function argument. | ||
func GetEnv(key string, fallback string) string { | ||
if value, ok := os.LookupEnv(key); ok { | ||
return value | ||
} | ||
return fallback | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package gonvutils | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestIsProduction(t *testing.T) { | ||
os.Setenv("ENVIRONMENT", "PROD") | ||
got := IsProduction() | ||
if got != true { | ||
t.Errorf("IsProduction() = %v; want true", got) | ||
} | ||
|
||
os.Setenv("ENVIRONMENT", "PRODUCTION") | ||
got = IsProduction() | ||
if got != true { | ||
t.Errorf("IsProduction() = %v; want true", got) | ||
} | ||
|
||
os.Setenv("ENVIRONMENT", "BLA") | ||
got = IsProduction() | ||
if got != false { | ||
t.Errorf("IsProduction() = %v; want false", got) | ||
} | ||
|
||
os.Unsetenv("ENVIRONMENT") | ||
} | ||
|
||
func TestIsDevelopment(t *testing.T) { | ||
os.Setenv("ENVIRONMENT", "DEV") | ||
got := IsDevelopment() | ||
if got != true { | ||
t.Errorf("IsDevelopment() = %v; want true", got) | ||
} | ||
|
||
os.Setenv("ENVIRONMENT", "DEVELOPMENT") | ||
got = IsDevelopment() | ||
if got != true { | ||
t.Errorf("IsDevelopment() = %v; want true", got) | ||
} | ||
|
||
os.Setenv("ENVIRONMENT", "BLA") | ||
got = IsDevelopment() | ||
if got != false { | ||
t.Errorf("IsDevelopment() = %v; want false", got) | ||
} | ||
|
||
os.Unsetenv("ENVIRONMENT") | ||
} | ||
|
||
func TestIsTesting(t *testing.T) { | ||
os.Setenv("ENVIRONMENT", "TEST") | ||
got := IsTesting() | ||
if got != true { | ||
t.Errorf("IsTesting() = %v; want true", got) | ||
} | ||
|
||
os.Setenv("ENVIRONMENT", "TESTING") | ||
got = IsTesting() | ||
if got != true { | ||
t.Errorf("IsTesting() = %v; want true", got) | ||
} | ||
|
||
os.Setenv("ENVIRONMENT", "BLA") | ||
got = IsTesting() | ||
if got != false { | ||
t.Errorf("IsTesting() = %v; want false", got) | ||
} | ||
|
||
os.Unsetenv("ENVIRONMENT") | ||
} | ||
|
||
func TestGetEnv(t *testing.T) { | ||
os.Setenv("SERVER_PORT", "8080") | ||
got := GetEnv("SERVER_PORT", "8080") | ||
if got != "8080" { | ||
t.Errorf("GetEnv(\"SERVER_PORT\", \"8080\") = %v; want 8080", got) | ||
} | ||
|
||
got = GetEnv("REDIS_PORT", "6379") | ||
if got != "6379" { | ||
t.Errorf("GetEnv(\"REDIS_PORT\", \"6379\") = %v; want 6379", got) | ||
} | ||
|
||
os.Unsetenv("SERVER_PORT") | ||
} |