diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..49468ed --- /dev/null +++ b/.air.toml @@ -0,0 +1,46 @@ +root = "." +testdata_dir = "testdata" +tmp_dir = "tmp" + +[build] + args_bin = [] + bin = "./tmp/main" + cmd = "go build -o ./tmp/main ." + delay = 1000 + exclude_dir = ["assets", "tmp", "vendor", "testdata"] + exclude_file = [] + exclude_regex = ["_test.go"] + exclude_unchanged = false + follow_symlink = false + full_bin = "" + include_dir = [] + include_ext = ["go", "tpl", "tmpl", "html"] + include_file = [] + kill_delay = "0s" + log = "build-errors.log" + poll = false + poll_interval = 0 + post_cmd = [] + pre_cmd = [] + rerun = false + rerun_delay = 500 + send_interrupt = false + stop_on_error = false + +[color] + app = "" + build = "yellow" + main = "magenta" + runner = "green" + watcher = "cyan" + +[log] + main_only = false + time = false + +[misc] + clean_on_exit = false + +[screen] + clear_on_rebuild = false + keep_scroll = true diff --git a/.gitignore b/.gitignore index 8bcdbd2..0717b2a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ **/.DS_Store -**/*.ps1 -**/*.sh +tmp/ diff --git a/db.go b/db.go index 2a609df..2b24e61 100644 --- a/db.go +++ b/db.go @@ -80,7 +80,7 @@ func PushAlbum(db *sqlx.DB, album music.Album) { } func InitDatabase() *sqlx.DB { - db, err := sqlx.Connect("postgres", "user=arimimi dbname=arimelody password=fuckingpassword sslmode=disable") + db, err := sqlx.Connect("postgres", "user=arimelody dbname=arimelody password=fuckingpassword sslmode=disable") if err != nil { fmt.Fprintf(os.Stderr, "unable to create database connection pool: %v\n", err) os.Exit(1) diff --git a/docker-compose-db.yml b/docker-compose-db.yml new file mode 100644 index 0000000..e873c50 --- /dev/null +++ b/docker-compose-db.yml @@ -0,0 +1,18 @@ +version: '3.9' + +services: + db: + image: postgres:16.1-alpine3.18 + container_name: arimelody.me-db + ports: + - 5432:5432 + volumes: + - arimelody-db:/var/lib/postgresql/data + environment: + POSTGRES_DB: arimelody + POSTGRES_USER: arimelody + POSTGRES_PASSWORD: fuckingpassword + +volumes: + arimelody-db: + external: true diff --git a/main.go b/main.go index f61983a..2c363fa 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,16 @@ package main import ( - "arimelody.me/arimelody.me/api/v1/music" - "fmt" "html/template" - "os" - "net/http" "log" - "strings" - "time" + "net/http" + "os" "strconv" + "strings" + "time" + + "arimelody.me/arimelody.me/api/v1/music" "github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown/html" @@ -20,14 +20,14 @@ import ( const PORT int = 8080 var mime_types = map[string]string{ - "css": "text/css; charset=utf-8", - "png": "image/png", - "jpg": "image/jpg", + "css": "text/css; charset=utf-8", + "png": "image/png", + "jpg": "image/jpg", "webp": "image/webp", "html": "text/html", - "asc": "text/plain", - "pub": "text/plain", - "js": "application/javascript", + "asc": "text/plain", + "pub": "text/plain", + "js": "application/javascript", } var templates = template.Must(template.ParseFiles( @@ -47,13 +47,13 @@ func log_request(req *http.Request, code int, start_time time.Time) { } fmt.Printf("[%s] %s %s - %d (%sms) (%s)\n", - now.Format(time.UnixDate), - req.Method, - req.URL.Path, + now.Format(time.UnixDate), + req.Method, + req.URL.Path, code, elapsed, - req.Header["User-Agent"][0], - ) + req.Header["User-Agent"][0], + ) } func web_handler(writer http.ResponseWriter, req *http.Request) { @@ -155,7 +155,7 @@ func static_handler(writer http.ResponseWriter, req *http.Request) int { } // setting MIME types - filetype := filename[strings.LastIndex(filename, ".") + 1:] + filetype := filename[strings.LastIndex(filename, ".")+1:] if mime_type, ok := mime_types[filetype]; ok { writer.Header().Set("Content-Type", mime_type) } else { @@ -172,7 +172,7 @@ func parse_markdown(md []byte) []byte { doc := p.Parse(md) htmlFlags := html.CommonFlags - opts := html.RendererOptions{ Flags: htmlFlags } + opts := html.RendererOptions{Flags: htmlFlags} renderer := html.NewRenderer(opts) return markdown.Render(doc, renderer)