Compare commits
No commits in common. 'fotogalerie' and 'master' have entirely different histories.
fotogaleri
...
master
@ -1,13 +1,36 @@ |
|||||||
FROM nginx:alpine |
FROM golang:alpine as builder |
||||||
|
|
||||||
COPY frontend/assets /usr/share/nginx/html/assets/ |
RUN apk --no-cache add --update \ |
||||||
COPY frontend/css /usr/share/nginx/html/css/ |
gcc \ |
||||||
COPY frontend/js /usr/share/nginx/html/js/ |
musl-dev \ |
||||||
COPY frontend/index.html /usr/share/nginx/html/ |
git \ |
||||||
|
ca-certificates |
||||||
|
WORKDIR /go/src/gitea.ckris.de/titzi/anmeldeportal_hochzeit |
||||||
|
RUN CGO_ENABLED=1 go get -d -v github.com/mattn/go-sqlite3 |
||||||
|
COPY backend/go/src/server/main.go . |
||||||
|
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o backend . |
||||||
|
|
||||||
RUN addgroup -g 3333 -S web && \ |
|
||||||
adduser -h /web -u 3333 -G web -S web && \ |
|
||||||
chown -R web:web . |
FROM alpine:latest |
||||||
USER web |
|
||||||
|
RUN apk --no-cache add --update \ |
||||||
|
gcc \ |
||||||
|
musl-dev |
||||||
|
|
||||||
|
WORKDIR /go/ |
||||||
|
|
||||||
|
COPY --from=builder /go/src/gitea.ckris.de/titzi/anmeldeportal_hochzeit/backend . |
||||||
|
COPY frontend/assets ./frontend/assets/ |
||||||
|
COPY frontend/js ./frontend/js/ |
||||||
|
COPY frontend/css ./frontend/css/ |
||||||
|
COPY frontend/index.html ./frontend/ |
||||||
|
|
||||||
|
RUN addgroup -g 3333 -S go && \ |
||||||
|
adduser -h /go -u 3333 -G go -S go && \ |
||||||
|
chown -R go:go . |
||||||
|
USER go |
||||||
|
|
||||||
EXPOSE 8080 |
EXPOSE 8080 |
||||||
|
|
||||||
|
CMD ["./backend"] |
||||||
@ -0,0 +1,184 @@ |
|||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"database/sql" |
||||||
|
"fmt" |
||||||
|
_ "github.com/mattn/go-sqlite3" |
||||||
|
"log" |
||||||
|
"net/http" |
||||||
|
"strconv" |
||||||
|
) |
||||||
|
|
||||||
|
type Response struct { |
||||||
|
FirstName, Name string |
||||||
|
Answer string |
||||||
|
NumAdult, NumKids uint |
||||||
|
Vegi, Vegan bool |
||||||
|
NumVegi, NumVegan uint |
||||||
|
Allerien bool |
||||||
|
Allergene string |
||||||
|
Accumodation bool |
||||||
|
NumRooms uint |
||||||
|
Arrival string |
||||||
|
Musik string |
||||||
|
Email string |
||||||
|
Permission bool |
||||||
|
Covid19 string |
||||||
|
} |
||||||
|
|
||||||
|
func newRespose(db *sql.DB, row *Response) error { |
||||||
|
sqlStmt := fmt.Sprintf(`INSERT INTO response |
||||||
|
(fName, lName, answer, numAdult, numKids, vegi, numVegi, vegan, numVegan, allergiger, allergene, accommodation, numRooms, arrival, musik, email, permission, covid19) |
||||||
|
VALUES |
||||||
|
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`) |
||||||
|
|
||||||
|
tx, err := db.Begin() |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
stmt, err := tx.Prepare(sqlStmt) |
||||||
|
defer tx.Commit() |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
defer stmt.Close() |
||||||
|
|
||||||
|
log.Printf("Add new response: %s", row) |
||||||
|
_, err = stmt.Exec( |
||||||
|
row.FirstName, row.Name, |
||||||
|
row.Answer, |
||||||
|
row.NumAdult, row.NumKids, |
||||||
|
row.Vegi, row.NumVegi, |
||||||
|
row.Vegan, row.NumVegan, |
||||||
|
row.Allerien, row.Allergene, |
||||||
|
row.Accumodation, row.NumRooms, |
||||||
|
row.Arrival, |
||||||
|
row.Musik, |
||||||
|
row.Email, row.Permission, |
||||||
|
row.Covid19, |
||||||
|
) |
||||||
|
if err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
func initDB(dbS string) (*sql.DB, error) { |
||||||
|
db, err := sql.Open("sqlite3", dbS) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
sqlStmt := fmt.Sprintf(`CREATE TABLE IF NOT EXISTS response |
||||||
|
(id INTEGER NOT NULL PRIMARY KEY, |
||||||
|
fName TEXT NOT NULL, lName TEXT NOT NULL, |
||||||
|
answer TEXT NOT NULL, |
||||||
|
numAdult INTEGER NOT NULL, numKids INTEGER NOT NULL, |
||||||
|
vegi BOOLEAN, numVegi INTEGER, |
||||||
|
vegan BOOLEAN, numVegan INTEGER, |
||||||
|
allergiger BOOLEAN, allergene TEXT, |
||||||
|
accommodation BOOLEAN, numRooms INTEGER, |
||||||
|
arrival TEXT, |
||||||
|
musik TEXT, |
||||||
|
email TEXT, permission BOOLEAN, |
||||||
|
covid19 TEXT, |
||||||
|
created DATETIME DEFAULT CURRENT_TIMESTAMP);`) |
||||||
|
_, err = db.Exec(sqlStmt) |
||||||
|
if err != nil { |
||||||
|
return db, err |
||||||
|
} |
||||||
|
|
||||||
|
log.Printf("DB %s is up and running", dbS) |
||||||
|
return db, nil |
||||||
|
} |
||||||
|
|
||||||
|
func main() { |
||||||
|
// init database
|
||||||
|
db, err := initDB("data/response.sqlite") |
||||||
|
if err != nil { |
||||||
|
if db != nil { |
||||||
|
db.Close() |
||||||
|
} |
||||||
|
log.Panic(err) |
||||||
|
} |
||||||
|
defer db.Close() |
||||||
|
|
||||||
|
// init http server with two routes for onepage website and endpoint for sending the response
|
||||||
|
// http.Handle("/", httpLogHandler(http.FileServer(http.Dir("../../../../frontend"))))
|
||||||
|
http.Handle("/", httpLogHandler(http.FileServer(http.Dir("./frontend")))) |
||||||
|
http.HandleFunc("/response", func(w http.ResponseWriter, r *http.Request) { |
||||||
|
processAnmeldung(w, r, db) |
||||||
|
}) |
||||||
|
|
||||||
|
http.ListenAndServe(":8080", nil) |
||||||
|
} |
||||||
|
|
||||||
|
func parseBool(s string) bool { |
||||||
|
return s == "on" |
||||||
|
} |
||||||
|
|
||||||
|
func parseUInt(s string) uint { |
||||||
|
u64, err := strconv.ParseUint(s, 10, 32) |
||||||
|
if err != nil { |
||||||
|
return 0 |
||||||
|
} |
||||||
|
return uint(u64) |
||||||
|
} |
||||||
|
|
||||||
|
func httpLogHandler(h http.Handler) http.Handler { |
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
||||||
|
log.Printf("Webseiten Aufruf: '%v:%v' %v", r.Method, r.URL, r.Header) |
||||||
|
h.ServeHTTP(w, r) |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
func processAnmeldung(w http.ResponseWriter, r *http.Request, db *sql.DB) { |
||||||
|
log.Printf("Process Endpoint Aufruf: '%v:%v' %v", r.Method, r.URL, r.Header) |
||||||
|
|
||||||
|
if r.Method != http.MethodPost { |
||||||
|
http.Redirect(w, r, "/", http.StatusSeeOther) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// Call ParseForm() to parse the raw query and update r.PostForm and r.Form.
|
||||||
|
if err := r.ParseForm(); err != nil { |
||||||
|
fmt.Fprintf(w, "ParseForm() err: %v", err) |
||||||
|
w.WriteHeader(http.StatusInternalServerError) |
||||||
|
return |
||||||
|
} |
||||||
|
log.Printf("Post from website: %v", r.PostForm) |
||||||
|
|
||||||
|
response := Response{ |
||||||
|
FirstName: r.FormValue("firstname"), |
||||||
|
Name: r.FormValue("name"), |
||||||
|
Answer: r.FormValue("rueckmeldung"), |
||||||
|
NumAdult: parseUInt(r.FormValue("numAdult")), |
||||||
|
NumKids: parseUInt(r.FormValue("numKids")), |
||||||
|
Vegi: parseBool(r.FormValue("vegi")), |
||||||
|
Vegan: parseBool(r.FormValue("vegan")), |
||||||
|
NumVegi: parseUInt(r.FormValue("numVegi")), |
||||||
|
NumVegan: parseUInt(r.FormValue("numVegan")), |
||||||
|
Allergene: r.FormValue("allagene"), |
||||||
|
Allerien: parseBool(r.FormValue("allergiger")), |
||||||
|
Accumodation: parseBool(r.FormValue("unterkunft")), |
||||||
|
Arrival: r.FormValue("arrival"), |
||||||
|
NumRooms: parseUInt(r.FormValue("numUnterkunft")), |
||||||
|
Musik: r.FormValue("musik"), |
||||||
|
Email: r.FormValue("email"), |
||||||
|
Permission: parseBool(r.FormValue("weitergabe")), |
||||||
|
Covid19: r.FormValue("covid19"), |
||||||
|
} |
||||||
|
log.Printf("Form values parsed: %v", response) |
||||||
|
|
||||||
|
err := newRespose(db, &response) |
||||||
|
if err != nil { |
||||||
|
log.Print("Fehler beim einfügen in die DB: %v", err) |
||||||
|
w.WriteHeader(http.StatusInternalServerError) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
//return success
|
||||||
|
w.WriteHeader(http.StatusCreated) |
||||||
|
} |
||||||
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 34 KiB |
|
After Width: | Height: | Size: 111 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 489 KiB |
|
Before Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 135 KiB |
|
Before Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 467 KiB |
|
Before Width: | Height: | Size: 455 KiB |
|
Before Width: | Height: | Size: 408 KiB |
|
Before Width: | Height: | Size: 304 KiB |
|
Before Width: | Height: | Size: 295 KiB |
|
Before Width: | Height: | Size: 384 KiB |
|
Before Width: | Height: | Size: 142 KiB |
|
Before Width: | Height: | Size: 172 KiB |
|
Before Width: | Height: | Size: 382 KiB |
|
Before Width: | Height: | Size: 476 KiB |
|
Before Width: | Height: | Size: 208 KiB |
|
Before Width: | Height: | Size: 268 KiB |
|
Before Width: | Height: | Size: 216 KiB |
|
Before Width: | Height: | Size: 124 KiB |
|
Before Width: | Height: | Size: 156 KiB |
|
Before Width: | Height: | Size: 209 KiB |
|
Before Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 332 KiB |
|
Before Width: | Height: | Size: 340 KiB |
|
Before Width: | Height: | Size: 504 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 168 KiB |
|
Before Width: | Height: | Size: 553 KiB |
|
Before Width: | Height: | Size: 149 KiB |
|
Before Width: | Height: | Size: 170 KiB |
|
Before Width: | Height: | Size: 150 KiB |
|
Before Width: | Height: | Size: 340 KiB |
|
Before Width: | Height: | Size: 436 KiB |
|
Before Width: | Height: | Size: 439 KiB |
|
Before Width: | Height: | Size: 328 KiB |
|
Before Width: | Height: | Size: 408 KiB |
|
Before Width: | Height: | Size: 531 KiB |
|
Before Width: | Height: | Size: 439 KiB |
|
Before Width: | Height: | Size: 420 KiB |
|
Before Width: | Height: | Size: 250 KiB |
|
Before Width: | Height: | Size: 482 KiB |
|
Before Width: | Height: | Size: 657 KiB |
|
Before Width: | Height: | Size: 483 KiB |
|
Before Width: | Height: | Size: 384 KiB |
|
Before Width: | Height: | Size: 121 KiB |
|
Before Width: | Height: | Size: 225 KiB |
|
Before Width: | Height: | Size: 151 KiB |
|
Before Width: | Height: | Size: 260 KiB |
|
Before Width: | Height: | Size: 235 KiB |
|
Before Width: | Height: | Size: 289 KiB |
|
Before Width: | Height: | Size: 149 KiB |
|
Before Width: | Height: | Size: 126 KiB |
|
Before Width: | Height: | Size: 127 KiB |
|
Before Width: | Height: | Size: 177 KiB |
|
Before Width: | Height: | Size: 296 KiB |
|
Before Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 412 KiB |
|
Before Width: | Height: | Size: 460 KiB |
|
Before Width: | Height: | Size: 438 KiB |
|
Before Width: | Height: | Size: 494 KiB |
|
Before Width: | Height: | Size: 466 KiB |
|
Before Width: | Height: | Size: 487 KiB |
|
Before Width: | Height: | Size: 222 KiB |
|
Before Width: | Height: | Size: 483 KiB |
|
Before Width: | Height: | Size: 176 KiB |
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 539 KiB |
|
Before Width: | Height: | Size: 351 KiB |
|
Before Width: | Height: | Size: 430 KiB |
|
Before Width: | Height: | Size: 175 KiB |
|
Before Width: | Height: | Size: 94 KiB |
|
Before Width: | Height: | Size: 271 KiB |
|
Before Width: | Height: | Size: 294 KiB |
|
Before Width: | Height: | Size: 245 KiB |
|
Before Width: | Height: | Size: 296 KiB |
|
Before Width: | Height: | Size: 184 KiB |
|
Before Width: | Height: | Size: 169 KiB |
|
Before Width: | Height: | Size: 165 KiB |
|
Before Width: | Height: | Size: 168 KiB |