Added DBName into CliArgs
This commit is contained in:
parent
1d91d0c216
commit
5e18ba52ad
@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CliArgs struct {
|
type CliArgs struct {
|
||||||
|
DBName string
|
||||||
KeyFile string
|
KeyFile string
|
||||||
LogFile string
|
LogFile string
|
||||||
PicsDir string
|
PicsDir string
|
||||||
@ -21,6 +22,7 @@ func HandleCliArgs() (*CliArgs, error) {
|
|||||||
logFile := flag.String("log", "/var/log/cpolis.log", "log file")
|
logFile := flag.String("log", "/var/log/cpolis.log", "log file")
|
||||||
picsDir := flag.String("pics", "/var/www/cpolis/pics", "pictures directory")
|
picsDir := flag.String("pics", "/var/www/cpolis/pics", "pictures directory")
|
||||||
webDir := flag.String("web", "/var/www/cpolis/web", "web directory")
|
webDir := flag.String("web", "/var/www/cpolis/web", "web directory")
|
||||||
|
flag.StringVar(&cliArgs.DBName, "db", "cpolis", "DB name")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
cliArgs.KeyFile, err = filepath.Abs(*keyFile)
|
cliArgs.KeyFile, err = filepath.Abs(*keyFile)
|
||||||
|
58
cmd/main.go
58
cmd/main.go
@ -16,67 +16,67 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cliArgs, err := control.HandleCliArgs()
|
args, err := control.HandleCliArgs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logFile, err := os.OpenFile(cliArgs.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
logFile, err := os.OpenFile(args.LogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
defer logFile.Close()
|
defer logFile.Close()
|
||||||
log.SetOutput(logFile)
|
log.SetOutput(logFile)
|
||||||
|
|
||||||
db, err := model.OpenDB("cpolis")
|
db, err := model.OpenDB(args.DBName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
key, err := control.LoadKey(cliArgs.KeyFile)
|
key, err := control.LoadKey(args.KeyFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
key, err = control.NewKey()
|
key, err = control.NewKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
control.SaveKey(key, cliArgs.KeyFile)
|
control.SaveKey(key, args.KeyFile)
|
||||||
}
|
}
|
||||||
store := control.NewCookieStore(key)
|
store := control.NewCookieStore(key)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
||||||
http.FileServer(http.Dir(cliArgs.WebDir+"/static/"))))
|
http.FileServer(http.Dir(args.WebDir+"/static/"))))
|
||||||
mux.HandleFunc("/", view.HomePage(cliArgs, db, store))
|
mux.HandleFunc("/", view.HomePage(args, db, store))
|
||||||
|
|
||||||
mux.HandleFunc("GET /create-tag/", view.CreateTag(cliArgs))
|
mux.HandleFunc("GET /create-tag/", view.CreateTag(args))
|
||||||
mux.HandleFunc("GET /create-user/", view.CreateUser(cliArgs))
|
mux.HandleFunc("GET /create-user/", view.CreateUser(args))
|
||||||
mux.HandleFunc("GET /edit-user/", view.EditUser(cliArgs, db, store))
|
mux.HandleFunc("GET /edit-user/", view.EditUser(args, db, store))
|
||||||
mux.HandleFunc("GET /hub/", view.ShowHub(cliArgs, db, store))
|
mux.HandleFunc("GET /hub/", view.ShowHub(args, db, store))
|
||||||
mux.HandleFunc("GET /logout/", view.Logout(cliArgs, store))
|
mux.HandleFunc("GET /logout/", view.Logout(args, store))
|
||||||
mux.HandleFunc("GET /publish-issue/", view.PublishLatestIssue(cliArgs, db, store))
|
mux.HandleFunc("GET /publish-issue/", view.PublishLatestIssue(args, db, store))
|
||||||
mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(cliArgs, db, store))
|
mux.HandleFunc("GET /rejected-articles/", view.ShowRejectedArticles(args, db, store))
|
||||||
mux.HandleFunc("GET /rss/", view.ShowRSS(cliArgs,
|
mux.HandleFunc("GET /rss/", view.ShowRSS(args,
|
||||||
db,
|
db,
|
||||||
"Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
"Freimaurer Distrikt Niedersachsen und Sachsen-Anhalt",
|
||||||
"https://distrikt-ni-st.de",
|
"https://distrikt-ni-st.de",
|
||||||
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität",
|
"Freiheit, Gleichheit, Brüderlichkeit, Toleranz und Humanität",
|
||||||
))
|
))
|
||||||
mux.HandleFunc("GET /this-issue/", view.ShowCurrentArticles(cliArgs, db))
|
mux.HandleFunc("GET /this-issue/", view.ShowCurrentArticles(args, db))
|
||||||
mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(cliArgs, db))
|
mux.HandleFunc("GET /unpublished-articles/", view.ShowUnpublishedArticles(args, db))
|
||||||
mux.HandleFunc("GET /write-article/", view.WriteArticle(cliArgs, db))
|
mux.HandleFunc("GET /write-article/", view.WriteArticle(args, db))
|
||||||
|
|
||||||
mux.HandleFunc("POST /add-tag/", view.AddTag(cliArgs, db, store))
|
mux.HandleFunc("POST /add-tag/", view.AddTag(args, db, store))
|
||||||
mux.HandleFunc("POST /add-user/", view.AddUser(cliArgs, db, store))
|
mux.HandleFunc("POST /add-user/", view.AddUser(args, db, store))
|
||||||
mux.HandleFunc("POST /login/", view.Login(cliArgs, db, store))
|
mux.HandleFunc("POST /login/", view.Login(args, db, store))
|
||||||
mux.HandleFunc("POST /publish-article/", view.PublishArticle(cliArgs, db, store))
|
mux.HandleFunc("POST /publish-article/", view.PublishArticle(args, db, store))
|
||||||
mux.HandleFunc("POST /reject-article/", view.RejectArticle(cliArgs, db, store))
|
mux.HandleFunc("POST /reject-article/", view.RejectArticle(args, db, store))
|
||||||
mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(cliArgs, db, store))
|
mux.HandleFunc("POST /resubmit-article/", view.ResubmitArticle(args, db, store))
|
||||||
mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(cliArgs, db, store))
|
mux.HandleFunc("POST /review-rejected-article/", view.ReviewRejectedArticle(args, db, store))
|
||||||
mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(cliArgs, db, store))
|
mux.HandleFunc("POST /review-unpublished-article/", view.ReviewUnpublishedArticle(args, db, store))
|
||||||
mux.HandleFunc("POST /submit-article/", view.SubmitArticle(cliArgs, db, store))
|
mux.HandleFunc("POST /submit-article/", view.SubmitArticle(args, db, store))
|
||||||
mux.HandleFunc("POST /update-user/", view.UpdateUser(cliArgs, db, store))
|
mux.HandleFunc("POST /update-user/", view.UpdateUser(args, db, store))
|
||||||
mux.HandleFunc("POST /upload-image/", view.UploadImage(cliArgs))
|
mux.HandleFunc("POST /upload-image/", view.UploadImage(args))
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(":8080", mux))
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ func UploadImage(c *control.CliArgs) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
filename := fmt.Sprint("tmp/pics/", time.Now().Format("2006-01-02_15:04:05"), "-", header.Filename)
|
filename := fmt.Sprint(c.PicsDir, time.Now().Format("2006-01-02_15:04:05"), "-", header.Filename)
|
||||||
img, err := os.Create(filename)
|
img, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user