aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-02-21 01:51:22 +0700
committerShulhan <ms@kilabit.info>2024-02-21 01:51:34 +0700
commitf08f1c15ff863d2829af8be8ddf392e9241d0f89 (patch)
tree1aa0066384ca66345cb526103c4b39797f30aa18
parente8d3716995e9229a61a32894689c379e22475420 (diff)
downloadgorankusu-f08f1c15ff863d2829af8be8ddf392e9241d0f89.tar.xz
all: move reading GORANKUSU_DEV environment to [Environment.IsDevelopment]
-rw-r--r--environment.go3
-rw-r--r--example.go3
-rw-r--r--gorankusu.go11
-rw-r--r--gorankusu_test.go2
-rw-r--r--internal/cmd/gorankusu/main.go11
5 files changed, 12 insertions, 18 deletions
diff --git a/environment.go b/environment.go
index 6b88b3e..ac9b602 100644
--- a/environment.go
+++ b/environment.go
@@ -58,6 +58,9 @@ type Environment struct {
// zero.
MaxAttackDuration time.Duration `ini:"gorankusu::max_attack_duration"`
+ // IsDevelopment if true run gorankusu in testing mode.
+ IsDevelopment bool
+
mtx sync.Mutex
}
diff --git a/example.go b/example.go
index f32847b..ae5866f 100644
--- a/example.go
+++ b/example.go
@@ -60,13 +60,14 @@ type Example struct {
}
// NewExample create, initialize, and setup an example of Gorankusu.
-func NewExample(listenAddress string) (ex *Example, err error) {
+func NewExample(listenAddress string, isDev bool) (ex *Example, err error) {
var logp = `NewExample`
var env = &Environment{
ListenAddress: listenAddress,
ResultsDir: `testdata/example/`,
ResultsSuffix: `example`,
+ IsDevelopment: isDev,
}
ex = &Example{}
diff --git a/gorankusu.go b/gorankusu.go
index b8aec82..dfec004 100644
--- a/gorankusu.go
+++ b/gorankusu.go
@@ -19,10 +19,6 @@ import (
// Version of gorankusu module.
const Version = `0.5.0`
-// EnvDevelopment setting this environment variable will enable gorankusu
-// development mode.
-const EnvDevelopment = "GORANKUSU_DEV"
-
// Gorankusu is the HTTP server with web user interface and APIs for running and
// load testing the registered HTTP endpoints.
type Gorankusu struct {
@@ -39,10 +35,7 @@ type Gorankusu struct {
// New create and initialize new Gorankusu service.
func New(env *Environment) (gorankusu *Gorankusu, err error) {
- var (
- logp = "gorankusu.New"
- isDevelopment = len(os.Getenv(EnvDevelopment)) > 0
- )
+ var logp = `New`
err = env.init()
if err != nil {
@@ -57,7 +50,7 @@ func New(env *Environment) (gorankusu *Gorankusu, err error) {
navLinks: make([]*NavLink, 0, 1),
}
- err = gorankusu.initHTTPServer(isDevelopment)
+ err = gorankusu.initHTTPServer(env.IsDevelopment)
if err != nil {
return nil, fmt.Errorf("%s: %w", logp, err)
}
diff --git a/gorankusu_test.go b/gorankusu_test.go
index 9435acc..15fa669 100644
--- a/gorankusu_test.go
+++ b/gorankusu_test.go
@@ -24,7 +24,7 @@ func TestMain(m *testing.M) {
// Mock crypto [rand.Reader] for predictable HTTP boundary.
rand.Reader = mock.NewRandReader([]byte(`gorankusu`))
- exGorankusu, err = NewExample(``)
+ exGorankusu, err = NewExample(``, false)
if err != nil {
log.Fatal(err)
}
diff --git a/internal/cmd/gorankusu/main.go b/internal/cmd/gorankusu/main.go
index f14e432..05ac508 100644
--- a/internal/cmd/gorankusu/main.go
+++ b/internal/cmd/gorankusu/main.go
@@ -35,18 +35,15 @@ func main() {
return
}
- var err = os.Setenv(gorankusu.EnvDevelopment, `1`)
- if err != nil {
- mlog.Fatalf(`%s`, err)
- }
-
var (
listenAddress = `127.0.0.1:18217`
+ isDev = true
- ex *gorankusu.Example
+ ex *gorankusu.Example
+ err error
)
- ex, err = gorankusu.NewExample(listenAddress)
+ ex, err = gorankusu.NewExample(listenAddress, isDev)
if err != nil {
mlog.Fatalf(`%s`, err)
}