Fixed recipe posting
This commit is contained in:
parent
491be9c1b1
commit
9ddafa9df8
1
.gitignore
vendored
1
.gitignore
vendored
@ -198,3 +198,4 @@ go.work
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
|
||||
/menuserver
|
||||
|
13
Makefile
13
Makefile
@ -1,18 +1,23 @@
|
||||
PROJECT = menuserver
|
||||
|
||||
VERSION = 3.0
|
||||
VERSION=`git describe --tags`
|
||||
BUILD=`date +%FT%T%z`
|
||||
|
||||
|
||||
ECR_REPO = git.caliban.io/martin
|
||||
# APP_IMAGE = 482681734622.dkr.ecr.eu-west-1.amazonaws.com/$(PROJECT):$(VERSION)
|
||||
|
||||
APP_IMAGE = $(ECR_REPO)/$(PROJECT):$(VERSION)
|
||||
# APP_IMAGE = $(PROJECT):$(VERSION)
|
||||
|
||||
NO_CACHE = true
|
||||
|
||||
LDFLAGS=-ldflags "-w -s -X main.Version=${VERSION} -X main.Build=${BUILD}"
|
||||
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
#CC=/usr/local/musl/bin/musl-gcc go build --ldflags '-linkmode external -extldflags "-static"' server.go
|
||||
GCO_ENABLED=0 GOOS=linux go build -o ${PROJECT} server.go
|
||||
# GCO_ENABLED=0 GOOS=linux go build ${LDFLAGS} -o ${PROJECT} server.go
|
||||
go build ${LDFLAGS} -o ${PROJECT} server.go
|
||||
|
||||
# docker build ./docker/. -t $(APP_IMAGE) --build-arg VERSION=$(VERSION) --no-cache=$(NO_CACHE) --compress=true
|
||||
docker build --platform linux/amd64 --no-cache -force-rm --tag ${APP_IMAGE} --file ./docker/Dockerfile .
|
||||
|
BIN
db/menu.db
BIN
db/menu.db
Binary file not shown.
@ -21,7 +21,7 @@ type MenuStrings struct {
|
||||
Hash string `json:"hash"`
|
||||
Meat string `json:"meat"`
|
||||
Mealtype string `json:"mealtype"`
|
||||
Lastused int64 `json:"lastused"`
|
||||
Lastused string `json:"lastused"`
|
||||
}
|
||||
|
||||
type InsertedType struct {
|
||||
|
@ -94,7 +94,7 @@ func (r *SQLiteRepository) GetOneHash(Hash string) (Menu, error) {
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (r *SQLiteRepository) InsertOne(newitem MenuStrings) (InsertedType, error) {
|
||||
func (r *SQLiteRepository) InsertOne(newitem Menu) (InsertedType, error) {
|
||||
log.Printf("Insert One: %s\n", newitem)
|
||||
|
||||
stmt, err := r.db.Prepare("INSERT INTO menu(name, url, md, short, hash, meat, mealtype, lastused) VALUES (?,?,?,?,?,?,?,?)")
|
||||
@ -105,11 +105,7 @@ func (r *SQLiteRepository) InsertOne(newitem MenuStrings) (InsertedType, error)
|
||||
|
||||
defer stmt.Close()
|
||||
|
||||
meat, _ := strconv.ParseInt(newitem.Meat, 10, 64)
|
||||
mealtype, _ := strconv.ParseInt(newitem.Meat, 10, 64)
|
||||
lastused, _ := strconv.ParseInt(newitem.Meat, 10, 64)
|
||||
|
||||
b, err := stmt.Exec(newitem.Name, newitem.Url, newitem.Md, newitem.Short, newitem.Hash, meat, mealtype, lastused)
|
||||
b, err := stmt.Exec(newitem.Name, newitem.Url, newitem.Md, newitem.Short, newitem.Hash, newitem.Meat, newitem.Mealtype, newitem.Lastused)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
18
docker-compose.yml
Normal file
18
docker-compose.yml
Normal file
@ -0,0 +1,18 @@
|
||||
version: '3.5'
|
||||
|
||||
services:
|
||||
menuserver:
|
||||
container_name: menuserver
|
||||
image: git.caliban.io/martin/menuserver:3.0.0
|
||||
restart: always
|
||||
ports:
|
||||
- "3000:3000"
|
||||
volumes:
|
||||
- ./db:/app/db
|
||||
environment:
|
||||
- EMAIL_FROM=Aida <aida@caliban.io>
|
||||
- EMAIL_LOGIN=aida@caliban.io
|
||||
- EMAIL_RECIPIENTS=Martin <martin@caliban.io>,Jessica <ing.arvid@gmail.com>
|
||||
- EMAIL_HOSTNAME=mail.caliban.io
|
||||
- EMAIL_PASSWORD=Ultra+Topaz+6XQ
|
||||
- SITE_URL=http://menu.lan
|
@ -10,6 +10,8 @@ COPY ./menuserver /app/
|
||||
|
||||
COPY ./dist /app/dist
|
||||
|
||||
RUN apt-get update && apt-get install -y ca-certificates
|
||||
|
||||
# Need the following to get a go app to run inside a docker container
|
||||
# as per: https://www.fairlyusefulcode.co.uk/post/go-alpine-linux/ -- DEAD!!!
|
||||
# RUN apk upgrade musl
|
||||
|
@ -7,15 +7,17 @@ import (
|
||||
"log"
|
||||
"menuserver/dbconnection"
|
||||
"net/smtp"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
from = "Aida <aida@caliban.io>"
|
||||
login = "aida@caliban.io"
|
||||
// recipients = []string{"Martin <martind2000@gmail.com>", "Jessica <ing.arvid@gmail.com>"}
|
||||
recipients = []string{"Martin <martind2000@gmail.com>"}
|
||||
hostname = "mail.caliban.io"
|
||||
from = os.Getenv("EMAIL_FROM")
|
||||
login = os.Getenv("EMAIL_LOGIN")
|
||||
recipients = strings.Split(os.Getenv("EMAIL_RECIPIENTS"), ",")
|
||||
// recipients = []string{"Martin <martind2000@gmail.com>"}
|
||||
hostname = os.Getenv("EMAIL_HOSTNAME")
|
||||
)
|
||||
|
||||
func DoJob(r *dbconnection.SQLiteRepository) {
|
||||
@ -26,7 +28,7 @@ func DoJob(r *dbconnection.SQLiteRepository) {
|
||||
|
||||
var menuItems []dbconnection.Menu
|
||||
|
||||
srcURL := "http://menu.lan"
|
||||
srcURL := os.Getenv("SITE_URL")
|
||||
var types = [7]int{0, 0, 0, 0, 0, 0, 0}
|
||||
limit := 2
|
||||
|
||||
@ -143,7 +145,7 @@ func sendSMTP(inmsg string, subject string) {
|
||||
|
||||
e := email.NewEmail()
|
||||
|
||||
auth := smtp.PlainAuth("", login, "Ultra+Topaz+6XQ", hostname)
|
||||
auth := smtp.PlainAuth("", login, os.Getenv("EMAIL_PASSWORD"), hostname)
|
||||
|
||||
e.From = from
|
||||
e.To = []string{from}
|
||||
|
8
notes.txt
Normal file
8
notes.txt
Normal file
@ -0,0 +1,8 @@
|
||||
EMAIL_FROM -- from = "Aida <aida@caliban.io>"
|
||||
EMAIL_LOGIN -- login = "aida@caliban.io"
|
||||
EMAIL_RECIPIENTS -- recipients = []string{"Martin <martind2000@gmail.com>", "Jessica <ing.arvid@gmail.com>"}
|
||||
// recipients = []string{"Martin <martind2000@gmail.com>"}
|
||||
EMAIL_HOSTNAME -- hostname = "mail.caliban.io"
|
||||
EMAIL_PASSWORD -- "Ultra+Topaz+6XQ"
|
||||
|
||||
SITE_URL -- srcURL := "http://menu.lan"
|
39
server.go
39
server.go
@ -24,13 +24,26 @@ const htmlFront = "<!DOCTYPE html>\n <html lang=\"en\">\n <head>\n
|
||||
const htmlEnd = "</div>\n \n </body>\n </html>"
|
||||
|
||||
var (
|
||||
version string
|
||||
build string
|
||||
Version string
|
||||
Build string
|
||||
startupErrors []string
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
fmt.Printf("Menu server v%+v build %+v\n\n", version, build)
|
||||
wanted := []string{"EMAIL_FROM", "EMAIL_LOGIN", "EMAIL_RECIPIENTS", "EMAIL_HOSTNAME", "EMAIL_PASSWORD", "SITE_URL"}
|
||||
|
||||
for _, item := range wanted {
|
||||
log.Printf("%+v -- %+v", item, os.Getenv(item))
|
||||
if len(os.Getenv(item)) == 0 {
|
||||
startupErrors = append(startupErrors, item)
|
||||
}
|
||||
}
|
||||
if len(startupErrors) != 0 {
|
||||
log.Fatal("Missing: ", strings.Join(startupErrors, ","))
|
||||
}
|
||||
|
||||
fmt.Printf("Menu server v%+v build %+v\n\n", Version, Build)
|
||||
|
||||
// setup connections n stuff
|
||||
|
||||
@ -89,6 +102,7 @@ func main() {
|
||||
})
|
||||
|
||||
c := cron.New()
|
||||
// "0 8 * * 6"
|
||||
var _, cronerr = c.AddFunc("0 8 * * 6", func() { jobhandler.DoJob(recipes) })
|
||||
if cronerr != nil {
|
||||
log.Fatal(cronerr)
|
||||
@ -224,17 +238,28 @@ func PostRecipeHandler(c *fiber.Ctx, r *dbconnection.SQLiteRepository) error {
|
||||
payload := dbconnection.MenuStrings{}
|
||||
|
||||
if err := c.BodyParser(&payload); err != nil {
|
||||
log.Println("PostRecipeHandler Bodyparser")
|
||||
log.Fatal(err)
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
payload.Hash = ShortHash(payload.Name)
|
||||
payload.Short = strcase.KebabCase(payload.Name)
|
||||
payload.Lastused = 0
|
||||
meat, _ := strconv.ParseInt(payload.Meat, 10, 64)
|
||||
mealtype, _ := strconv.ParseInt(payload.Mealtype, 10, 64)
|
||||
|
||||
usePayload := dbconnection.Menu{
|
||||
Name: payload.Name,
|
||||
Url: payload.Url,
|
||||
Md: payload.Md,
|
||||
Short: strcase.KebabCase(payload.Name),
|
||||
Hash: ShortHash(payload.Name),
|
||||
Meat: meat,
|
||||
Mealtype: mealtype,
|
||||
Lastused: 0,
|
||||
}
|
||||
|
||||
var returnVal dbconnection.InsertedType
|
||||
returnVal, _ = r.InsertOne(payload)
|
||||
returnVal, _ = r.InsertOne(usePayload)
|
||||
|
||||
jsonStr, err := json.Marshal(returnVal)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user