made cross-platform development easier

Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
ari melody 2024-03-20 07:14:05 +00:00
parent 4b5e6a50ff
commit 9d56ca63af
5 changed files with 85 additions and 22 deletions

46
.air.toml Normal file
View file

@ -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

3
.gitignore vendored
View file

@ -1,3 +1,2 @@
**/.DS_Store **/.DS_Store
**/*.ps1 tmp/
**/*.sh

2
db.go
View file

@ -80,7 +80,7 @@ func PushAlbum(db *sqlx.DB, album music.Album) {
} }
func InitDatabase() *sqlx.DB { 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 { if err != nil {
fmt.Fprintf(os.Stderr, "unable to create database connection pool: %v\n", err) fmt.Fprintf(os.Stderr, "unable to create database connection pool: %v\n", err)
os.Exit(1) os.Exit(1)

18
docker-compose-db.yml Normal file
View file

@ -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

38
main.go
View file

@ -1,16 +1,16 @@
package main package main
import ( import (
"arimelody.me/arimelody.me/api/v1/music"
"fmt" "fmt"
"html/template" "html/template"
"os"
"net/http"
"log" "log"
"strings" "net/http"
"time" "os"
"strconv" "strconv"
"strings"
"time"
"arimelody.me/arimelody.me/api/v1/music"
"github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html" "github.com/gomarkdown/markdown/html"
@ -20,14 +20,14 @@ import (
const PORT int = 8080 const PORT int = 8080
var mime_types = map[string]string{ var mime_types = map[string]string{
"css": "text/css; charset=utf-8", "css": "text/css; charset=utf-8",
"png": "image/png", "png": "image/png",
"jpg": "image/jpg", "jpg": "image/jpg",
"webp": "image/webp", "webp": "image/webp",
"html": "text/html", "html": "text/html",
"asc": "text/plain", "asc": "text/plain",
"pub": "text/plain", "pub": "text/plain",
"js": "application/javascript", "js": "application/javascript",
} }
var templates = template.Must(template.ParseFiles( 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", fmt.Printf("[%s] %s %s - %d (%sms) (%s)\n",
now.Format(time.UnixDate), now.Format(time.UnixDate),
req.Method, req.Method,
req.URL.Path, req.URL.Path,
code, code,
elapsed, elapsed,
req.Header["User-Agent"][0], req.Header["User-Agent"][0],
) )
} }
func web_handler(writer http.ResponseWriter, req *http.Request) { 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 // setting MIME types
filetype := filename[strings.LastIndex(filename, ".") + 1:] filetype := filename[strings.LastIndex(filename, ".")+1:]
if mime_type, ok := mime_types[filetype]; ok { if mime_type, ok := mime_types[filetype]; ok {
writer.Header().Set("Content-Type", mime_type) writer.Header().Set("Content-Type", mime_type)
} else { } else {
@ -172,7 +172,7 @@ func parse_markdown(md []byte) []byte {
doc := p.Parse(md) doc := p.Parse(md)
htmlFlags := html.CommonFlags htmlFlags := html.CommonFlags
opts := html.RendererOptions{ Flags: htmlFlags } opts := html.RendererOptions{Flags: htmlFlags}
renderer := html.NewRenderer(opts) renderer := html.NewRenderer(opts)
return markdown.Render(doc, renderer) return markdown.Render(doc, renderer)