added publish option
This commit is contained in:
parent
5cac64d907
commit
700983cb12
|
@ -1,2 +1,3 @@
|
||||||
comics
|
comics
|
||||||
db.sqlite
|
db.sqlite
|
||||||
|
media
|
29
comics.go
29
comics.go
|
@ -38,7 +38,7 @@ func (c *Comic) readRow(db * sql.Rows) error {
|
||||||
const dbSquema string = `
|
const dbSquema string = `
|
||||||
CREATE TABLE IF NOT EXISTS comic (
|
CREATE TABLE IF NOT EXISTS comic (
|
||||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
datetime DATETIME NOT NULL,
|
datetime DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
title CHAR(50),
|
title CHAR(50),
|
||||||
image CHAR(200),
|
image CHAR(200),
|
||||||
description TEXT,
|
description TEXT,
|
||||||
|
@ -221,6 +221,12 @@ func return500(w http.ResponseWriter, r * http.Request) {
|
||||||
returnError(w, r, http.StatusInternalServerError)
|
returnError(w, r, http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newComic(title string, image string, description string, tags string) error {
|
||||||
|
_, err := db.Exec("INSERT INTO comic(title, image, description, tags) VALUES(?, ?, ?, ?);",
|
||||||
|
title, image, description, tags)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -238,6 +244,12 @@ func main() {
|
||||||
Required: false, Help: "Defines the address the web server will listen to", Default: "127.0.0.1"})
|
Required: false, Help: "Defines the address the web server will listen to", Default: "127.0.0.1"})
|
||||||
port := parser.Int("p", "port", &argparse.Options{
|
port := parser.Int("p", "port", &argparse.Options{
|
||||||
Required: false, Help: "Defines the port the web server will listen to", Default: 8080})
|
Required: false, Help: "Defines the port the web server will listen to", Default: 8080})
|
||||||
|
publish := parser.Flag("u", "publish", &argparse.Options{
|
||||||
|
Required: false, Help: "Creates new commics. Needs both -i and -l", Default: false})
|
||||||
|
title := parser.String("l", "title", &argparse.Options{
|
||||||
|
Required: false, Help: "Title for new comic", Default: ""})
|
||||||
|
image := parser.String("i", "image", &argparse.Options{
|
||||||
|
Required: false, Help: "Image path for new comic", Default: ""})
|
||||||
|
|
||||||
err = parser.Parse(os.Args)
|
err = parser.Parse(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -256,6 +268,21 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if *publish {
|
||||||
|
if len(*image) < 1 {
|
||||||
|
panic("missing -i")
|
||||||
|
}
|
||||||
|
if len(*title) < 1 {
|
||||||
|
panic("missing -l")
|
||||||
|
}
|
||||||
|
err = newComic(*title, *image, "", "")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Println(fmt.Sprintf("comic \"%s\" created", *title))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// views
|
// views
|
||||||
http.HandleFunc("/", indexView)
|
http.HandleFunc("/", indexView)
|
||||||
http.HandleFunc("/latest", latestView)
|
http.HandleFunc("/latest", latestView)
|
||||||
|
|
Loading…
Reference in New Issue