diff --git a/go.mod b/go.mod index b0dc191670b63b8815e9b19e72c4cd560704573e..0003a829ea2b9b6f4f4fc4c8b85f54b34f73a15a 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,9 @@ module gitlab.reutlingen-university.de/albrecht/myaktion-go go 1.20 -require github.com/gorilla/mux v1.8.0 +require ( + github.com/gorilla/mux v1.8.0 + github.com/sirupsen/logrus v1.9.0 +) + +require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect diff --git a/go.sum b/go.sum index 535028803d222b0e4e9174f56529c0ed9fece4e0..656e662af702e4a5983da10a62dbb3adda6130ce 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,17 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main/main.go b/main/main.go index 1f2f41b393c63ff5d743fbaa5ab9f0f691e9260f..7057e32cd89af4a225857c5f248fcfc9679fdee1 100644 --- a/main/main.go +++ b/main/main.go @@ -1,8 +1,10 @@ package main import ( - "log" "net/http" + "os" + + log "github.com/sirupsen/logrus" "github.com/gorilla/mux" "gitlab.reutlingen-university.de/albrecht/myaktion-go/src/myaktion/handler" @@ -10,10 +12,25 @@ import ( //"gitlab.reutlingen-university.de/albrecht/myaktion-go/src/myaktion/model" +func init() { + // init logger + log.SetFormatter(&log.TextFormatter{}) + log.SetReportCaller(true) + level, err := log.ParseLevel(os.Getenv("LOG_LEVEL")) + if err != nil { + log.Info("Log level not specified, set default to: INFO") + log.SetLevel(log.InfoLevel) + return + } + log.SetLevel(level) +} + func main() { log.Println("Starting My-Aktion API server") router := mux.NewRouter() router.HandleFunc("/health", handler.Health).Methods("GET") + router.HandleFunc("/campaign", handler.CreateCampaign).Methods("POST") + router.HandleFunc("/campaigns", handler.GetCampaigns).Methods("GET") if err := http.ListenAndServe(":8000", router); err != nil { log.Fatal(err) } diff --git a/src/myaktion/model/campaign.go b/src/myaktion/model/campaign.go index 233c9c104e172c06cc9f185507c4f7a652f55e0b..9fb581918dccfb6439fe2b276700060d13d6c517 100644 --- a/src/myaktion/model/campaign.go +++ b/src/myaktion/model/campaign.go @@ -1,6 +1,7 @@ package model -type Camaign struct { +type Campaign struct { + ID uint Name string OrganizerName string TargetAmount float64