Skip to content
Snippets Groups Projects
Commit b82f3f20 authored by Emanuel Petrinovic's avatar Emanuel Petrinovic
Browse files

add handler and health check

parent 1e3d381b
No related branches found
No related tags found
No related merge requests found
module gitlab.reutlingen-university.de/petrinov/myaktion-go module gitlab.reutlingen-university.de/petrinov/myaktion-go
go 1.24.2 go 1.24.2
require github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
package handler
import (
"io"
"net/http"
)
func Health(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
io.WriteString(w, `{"alive": true}`)
}
package main package main
import ( import (
"fmt" "log"
"net/http"
"gitlab.reutlingen-university.de/petrinov/myaktion-go/model" "github.com/gorilla/mux"
"gitlab.reutlingen-university.de/petrinov/myaktion-go/handler"
) )
func main() { func main() {
log.Println("Starting My-Aktion API server")
newAccount := model.Account{ router := mux.NewRouter()
Name: "NeuerAccount", router.HandleFunc("/health", handler.Health).Methods("GET")
BankName: "NeueBank", if err := http.ListenAndServe(":8000", router); err != nil {
Number: "1", log.Fatal(err)
}
newAccount2 := model.Account{
Name: "NeuerAccount3",
BankName: "NeueBank3",
Number: "2",
}
newAccount3 := model.Account{
Name: "NeuerAccount3",
BankName: "NeueBank3",
Number: "3",
}
donation1 := model.Donation{
Ammount: 10.00,
DonorName: "Irgendwer",
ReceiptRequested: false,
Account: newAccount2,
}
donation2 := model.Donation{
Ammount: 5.00,
DonorName: "Irgendwo",
ReceiptRequested: true,
Account: newAccount3,
} }
newCampagin := model.Campaign{
Name: "Neue Campaign",
OrganizerName: "Aktion Mensch",
TargetAmmount: 100.00,
DonationMinimum: 20.00,
AmmountDonatedSoFar: 80.00,
Account: newAccount,
Donations: []model.Donation{donation1, donation2},
}
fmt.Println(newCampagin)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment