Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
6de584aa
Commit
6de584aa
authored
Apr 12, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated to config file finding, and added homepath command line option
parent
cc427b13
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
23 deletions
+51
-23
conf/dev.ini
+0
-10
main.go
+2
-0
pkg/setting/setting.go
+40
-7
pkg/setting/setting_test.go
+9
-6
No files found.
conf/dev.ini
deleted
100644 → 0
View file @
cc427b13
app_mode
=
development
[server]
router_logging
=
false
[log]
level
=
Trace
main.go
View file @
6de584aa
...
...
@@ -25,6 +25,7 @@ var commit = "NA"
var
buildstamp
string
var
configFile
=
flag
.
String
(
"config"
,
""
,
"path to config file"
)
var
homePath
=
flag
.
String
(
"homepath"
,
""
,
"path to grafana install/home path, defaults to working directory"
)
var
pidFile
=
flag
.
String
(
"pidfile"
,
""
,
"path to pid file"
)
func
init
()
{
...
...
@@ -66,6 +67,7 @@ func main() {
func
initRuntime
()
{
setting
.
NewConfigContext
(
&
setting
.
CommandLineArgs
{
Config
:
*
configFile
,
HomePath
:
*
homePath
,
Args
:
flag
.
Args
(),
})
...
...
pkg/setting/setting.go
View file @
6de584aa
...
...
@@ -107,13 +107,13 @@ var (
type
CommandLineArgs
struct
{
Config
string
HomePath
string
Args
[]
string
}
func
init
()
{
IsWindows
=
runtime
.
GOOS
==
"windows"
log
.
NewLogger
(
0
,
"console"
,
`{"level": 0}`
)
HomePath
,
_
=
filepath
.
Abs
(
"."
)
}
func
parseAppUrlAndSubUrl
(
section
*
ini
.
Section
)
(
string
,
string
)
{
...
...
@@ -226,6 +226,14 @@ func evalConfigValues() {
}
func
loadSpecifedConfigFile
(
configFile
string
)
{
if
configFile
==
""
{
configFile
=
filepath
.
Join
(
HomePath
,
"conf/custom.ini"
)
// return without error if custom file does not exist
if
!
pathExists
(
configFile
)
{
return
}
}
userConfig
,
err
:=
ini
.
Load
(
configFile
)
userConfig
.
BlockMode
=
false
if
err
!=
nil
{
...
...
@@ -256,8 +264,6 @@ func loadSpecifedConfigFile(configFile string) {
func
loadConfiguration
(
args
*
CommandLineArgs
)
{
var
err
error
args
.
Config
=
evalEnvVarExpression
(
args
.
Config
)
// load config defaults
defaultConfigFile
:=
path
.
Join
(
HomePath
,
"conf/defaults.ini"
)
configFiles
=
append
(
configFiles
,
defaultConfigFile
)
...
...
@@ -276,9 +282,7 @@ func loadConfiguration(args *CommandLineArgs) {
applyCommandLineDefaultProperties
(
commandLineProps
)
// load specified config file
if
args
.
Config
!=
""
{
loadSpecifedConfigFile
(
args
.
Config
)
}
// apply environment overrides
applyEnvVariableOverrides
()
...
...
@@ -290,11 +294,40 @@ func loadConfiguration(args *CommandLineArgs) {
evalConfigValues
()
}
func
pathExists
(
path
string
)
bool
{
_
,
err
:=
os
.
Stat
(
path
)
if
err
==
nil
{
return
true
}
if
os
.
IsNotExist
(
err
)
{
return
false
}
return
false
}
func
setHomePath
(
args
*
CommandLineArgs
)
{
if
args
.
HomePath
!=
""
{
HomePath
=
args
.
HomePath
return
}
HomePath
,
_
=
filepath
.
Abs
(
"."
)
// check if homepath is correct
if
pathExists
(
filepath
.
Join
(
HomePath
,
"conf/defaults.ini"
))
{
return
}
// try down one path
if
pathExists
(
filepath
.
Join
(
HomePath
,
"../conf/defaults.ini"
))
{
HomePath
=
filepath
.
Join
(
HomePath
,
"../"
)
}
}
func
NewConfigContext
(
args
*
CommandLineArgs
)
{
setHomePath
(
args
)
loadConfiguration
(
args
)
DataPath
=
makeAbsolute
(
Cfg
.
Section
(
"paths"
)
.
Key
(
"data"
)
.
String
(),
HomePath
)
initLogging
(
args
)
AppName
=
Cfg
.
Section
(
""
)
.
Key
(
"app_name"
)
.
MustString
(
"Grafana"
)
...
...
@@ -314,7 +347,7 @@ func NewConfigContext(args *CommandLineArgs) {
HttpAddr
=
server
.
Key
(
"http_addr"
)
.
MustString
(
"0.0.0.0"
)
HttpPort
=
server
.
Key
(
"http_port"
)
.
MustString
(
"3000"
)
StaticRootPath
=
server
.
Key
(
"static_root_path"
)
.
MustString
(
path
.
Join
(
HomePath
,
"public"
)
)
StaticRootPath
=
makeAbsolute
(
server
.
Key
(
"static_root_path"
)
.
String
(),
HomePath
)
RouterLogging
=
server
.
Key
(
"router_logging"
)
.
MustBool
(
false
)
EnableGzip
=
server
.
Key
(
"enable_gzip"
)
.
MustBool
(
false
)
...
...
pkg/setting/setting_test.go
View file @
6de584aa
...
...
@@ -10,12 +10,10 @@ import (
func
TestLoadingSettings
(
t
*
testing
.
T
)
{
HomePath
,
_
=
filepath
.
Abs
(
"../../"
)
Convey
(
"Testing loading settings from ini file"
,
t
,
func
()
{
Convey
(
"Given the default ini files"
,
func
()
{
NewConfigContext
(
&
CommandLineArgs
{})
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
})
So
(
AppName
,
ShouldEqual
,
"Grafana"
)
So
(
AdminUser
,
ShouldEqual
,
"admin"
)
...
...
@@ -23,7 +21,7 @@ func TestLoadingSettings(t *testing.T) {
Convey
(
"Should be able to override via environment variables"
,
func
()
{
os
.
Setenv
(
"GF_SECURITY_ADMIN_USER"
,
"superduper"
)
NewConfigContext
(
&
CommandLineArgs
{})
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
})
So
(
AdminUser
,
ShouldEqual
,
"superduper"
)
So
(
DataPath
,
ShouldEqual
,
filepath
.
Join
(
HomePath
,
"data"
))
...
...
@@ -40,6 +38,7 @@ func TestLoadingSettings(t *testing.T) {
Convey
(
"Should be able to override via command line"
,
func
()
{
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
,
Args
:
[]
string
{
"cfg:paths.data=/tmp/data"
,
"cfg:paths.logs=/tmp/logs"
},
})
...
...
@@ -49,6 +48,7 @@ func TestLoadingSettings(t *testing.T) {
Convey
(
"Should be able to override defaults via command line"
,
func
()
{
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
,
Args
:
[]
string
{
"cfg:default.server.domain=test2"
,
},
...
...
@@ -60,8 +60,9 @@ func TestLoadingSettings(t *testing.T) {
Convey
(
"Defaults can be overriden in specified config file"
,
func
()
{
NewConfigContext
(
&
CommandLineArgs
{
Args
:
[]
string
{
"cfg:default.paths.data=/tmp/data"
}
,
HomePath
:
"../../"
,
Config
:
filepath
.
Join
(
HomePath
,
"tests/config-files/override.ini"
),
Args
:
[]
string
{
"cfg:default.paths.data=/tmp/data"
},
})
So
(
DataPath
,
ShouldEqual
,
"/tmp/override"
)
...
...
@@ -69,8 +70,9 @@ func TestLoadingSettings(t *testing.T) {
Convey
(
"Command line overrides specified config file"
,
func
()
{
NewConfigContext
(
&
CommandLineArgs
{
Args
:
[]
string
{
"cfg:paths.data=/tmp/data"
}
,
HomePath
:
"../../"
,
Config
:
filepath
.
Join
(
HomePath
,
"tests/config-files/override.ini"
),
Args
:
[]
string
{
"cfg:paths.data=/tmp/data"
},
})
So
(
DataPath
,
ShouldEqual
,
"/tmp/data"
)
...
...
@@ -79,6 +81,7 @@ func TestLoadingSettings(t *testing.T) {
Convey
(
"Can use environment variables in config values"
,
func
()
{
os
.
Setenv
(
"GF_DATA_PATH"
,
"/tmp/env_override"
)
NewConfigContext
(
&
CommandLineArgs
{
HomePath
:
"../../"
,
Args
:
[]
string
{
"cfg:paths.data=${GF_DATA_PATH}"
},
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment