Skip to content

Commit b13f33a

Browse files
committed
generate config file
1 parent 749fc16 commit b13f33a

File tree

3 files changed

+88
-11
lines changed

3 files changed

+88
-11
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.idea/
2+
.DS_Store
3+
output/
4+
dist/
5+
6+
# Binaries for programs and plugins
7+
*.exe
8+
*.exe~
9+
*.dll
10+
*.so
11+
*.dylib
12+
*.db
13+
*.bin
14+
15+
# Test binary, built with `go test -c`
16+
*.test
17+
18+
# Output of the go coverage tool, specifically when used with LiteIDE
19+
*.out
20+
21+
# Dependency directories (remove the comment below to include it)
22+
# vendor/
23+
bin/*

entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mkdir -p /opt/alist/data/
12
/main
23

34
cd /opt/alist

main.go

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,79 @@
11
package main
2+
23
import (
4+
"encoding/json"
35
"fmt"
6+
"io/ioutil"
7+
"log"
48
"net/url"
59
"os"
10+
"strconv"
611
)
712

13+
type Database struct {
14+
Type string `json:"type" env:"DB_TYPE"`
15+
Host string `json:"host" env:"DB_HOST"`
16+
Port int `json:"port" env:"DB_PORT"`
17+
User string `json:"user" env:"DB_USER"`
18+
Password string `json:"password" env:"DB_PASS"`
19+
Name string `json:"name" env:"DB_NAME"`
20+
DBFile string `json:"db_file" env:"DB_FILE"`
21+
TablePrefix string `json:"table_prefix" env:"DB_TABLE_PREFIX"`
22+
SslMode string `json:"ssl_mode" env:"DB_SLL_MODE"`
23+
}
24+
25+
type Scheme struct {
26+
Https bool `json:"https" env:"HTTPS"`
27+
CertFile string `json:"cert_file" env:"CERT_FILE"`
28+
KeyFile string `json:"key_file" env:"KEY_FILE"`
29+
}
30+
31+
type CacheConfig struct {
32+
Expiration int64 `json:"expiration" env:"CACHE_EXPIRATION"`
33+
CleanupInterval int64 `json:"cleanup_interval" env:"CLEANUP_INTERVAL"`
34+
}
35+
36+
type Config struct {
37+
Force bool `json:"force"`
38+
Address string `json:"address" env:"ADDR"`
39+
Port int `json:"port" env:"PORT"`
40+
Assets string `json:"assets" env:"ASSETS"`
41+
Database Database `json:"database"`
42+
Scheme Scheme `json:"scheme"`
43+
Cache CacheConfig `json:"cache"`
44+
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
45+
}
46+
847
func main() {
9-
DatabaseUrl := os.Getenv("DATABASE_URL")
10-
fmt.Println("DatabaseUrl",DatabaseUrl)
11-
// DATABASE_URL = postgres://user3123:passkja83kd8@ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398
12-
u, err := url.Parse(DatabaseUrl)
48+
DATABASE_URL := os.Getenv("DATABASE_URL")
49+
fmt.Println("DatabaseUrl", DATABASE_URL)
50+
DATABASE_URL = "postgres://user3123:passkja83kd8@ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398"
51+
u, err := url.Parse(DATABASE_URL)
1352
if err != nil {
1453
fmt.Println(err)
1554
}
1655
user := u.User.Username()
1756
pass, _ := u.User.Password()
1857
host := u.Hostname()
19-
port := u.Port()
58+
port, _ := strconv.Atoi(u.Port())
2059
name := u.Path[1:]
21-
_ = os.Setenv("DB_HOST", host)
22-
_ = os.Setenv("DB_PORT", port)
23-
_ = os.Setenv("DB_USER", user)
24-
_ = os.Setenv("DB_PASS", pass)
25-
_ = os.Setenv("DB_NAME", name)
26-
}
60+
config := Config{
61+
Address: "0.0.0.0",
62+
TempDir: "data/temp",
63+
Database: Database{
64+
User: user,
65+
Password: pass,
66+
Host: host,
67+
Port: port,
68+
Name: name,
69+
},
70+
}
71+
confBody, err := json.MarshalIndent(config, "", " ")
72+
if err != nil {
73+
log.Fatalf("failed marshal json: %s", err.Error())
74+
}
75+
err = ioutil.WriteFile("/opt/alist/data/config.json", confBody, 0777)
76+
if err != nil {
77+
log.Fatalf("failed write json: %s", err.Error())
78+
}
79+
}

0 commit comments

Comments
 (0)