Skip to content

Commit 2a3eb4a

Browse files
committed
Using $HOME/.armor for config and db
Signed-off-by: Vishal Rana <[email protected]>
1 parent fceea89 commit 2a3eb4a

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGE = labstack/armor
2-
VERSION = 0.4.2
2+
VERSION = 0.4.3
33

44
clean:
55
rm -rf build

armor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ type (
8989
)
9090

9191
const (
92-
Version = "0.4.2"
92+
Version = "0.4.3"
9393
Website = "https://armor.labstack.com"
9494
)
9595

cmd/armor/main.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/labstack/armor/util"
2020
"github.com/labstack/gommon/color"
2121
"github.com/labstack/gommon/log"
22+
"github.com/mitchellh/go-homedir"
2223
)
2324

2425
const (
@@ -111,8 +112,18 @@ func main() {
111112
Colorer: colorer,
112113
}
113114

115+
// Home dir
116+
homeDir, err := homedir.Dir()
117+
if err != nil {
118+
log.Fatalf("Failed to find home directory %v\n", err)
119+
}
120+
configDir := filepath.Join(homeDir, ".armor")
121+
if err = os.MkdirAll(configDir, 0755); err != nil {
122+
log.Fatalf("Failed to create config directory %v\n", err)
123+
}
124+
114125
// Global flags
115-
config := flag.String("c", "", "config file")
126+
config := flag.String("c", filepath.Join(configDir, "config.yaml"), "config file")
116127
port := flag.String("p", "", "listen port")
117128
version := flag.Bool("v", false, "armor version")
118129

@@ -139,7 +150,7 @@ func main() {
139150
}
140151

141152
// Config - start
142-
// Load
153+
// Load config
143154
data, err := ioutil.ReadFile(*config)
144155
if err != nil {
145156
// Use default config
@@ -155,19 +166,13 @@ func main() {
155166
a.Address = net.JoinHostPort("", *port)
156167
}
157168

158-
// Working directory
159-
wd, err := os.Getwd()
160-
if err != nil {
161-
logger.Fatal(err)
162-
}
163-
164169
// Defaults
165170
if a.Address == "" {
166171
a.Address = ":80"
167172
}
168173
if a.SQLite == nil {
169174
a.SQLite = &armor.SQLite{
170-
URI: filepath.Join(wd, "armor.db"),
175+
URI: filepath.Join(configDir, "db"),
171176
}
172177
}
173178
if a.Admin == nil {

website/content/guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Type `armor` in your terminal
3838
___
3939
/ _ | ______ _ ___ ____
4040
/ __ |/ __/ ' \/ _ \/ __/
41-
/_/ |_/_/ /_/_/_/\___/_/ v0.4.2
41+
/_/ |_/_/ /_/_/_/\___/_/ v0.4.3
4242
4343
Uncomplicated, modern HTTP server
4444
https://armor.labstack.com

0 commit comments

Comments
 (0)