Skip to content

Commit

Permalink
Update gapi exemples with version v0.2.0 and go 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuma committed May 29, 2023
1 parent 596e77a commit ec2659a
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 32 deletions.
4 changes: 2 additions & 2 deletions examples/1-hello-world/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/mwm-io/gapi/examples/1-hello-world

go 1.18
go 1.19

require github.com/mwm-io/gapi v0.1.0
require github.com/mwm-io/gapi v0.2.0

require (
github.com/elnormous/contenttype v1.0.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/1-hello-world/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/mwm-io/gapi v0.1.0 h1:KT4J6uwNX9uSZaeHcZzM2eR3zgSqGhyUY7UY4Tf9ZRc=
github.com/mwm-io/gapi v0.1.0/go.mod h1:kGkSeloZf2LJK1tqdgbUFK10MzBQVFjolpOCMnwEXRM=
github.com/mwm-io/gapi v0.2.0 h1:jhpCAHIZkuftPk5nIOISag2nC4Eq4FwjzwSHYIlSib4=
github.com/mwm-io/gapi v0.2.0/go.mod h1:gPTxM9Fhgn7m3+5angXq8+63tTToHbYb9JDTibJJYek=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
8 changes: 5 additions & 3 deletions examples/1-hello-world/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"net/http"

"github.com/mwm-io/gapi/handler"
Expand All @@ -9,16 +10,17 @@ import (
)

func main() {
ctx := context.Background()
r := server.NewMux()

server.AddHandler(r, "GET", "/", handler.Func(HelloWorldHandler))

gLog.Info("Starting http server")
gLog.Info(ctx, "Starting http server")
if err := server.ServeAndHandleShutdown(r); err != nil {
gLog.Emergency(err.Error())
gLog.Emergency(ctx, err.Error())
}

gLog.Info("Server stopped")
gLog.Info(ctx, "Server stopped")
}

// HelloWorldHandler is the simplest handler with core middlewares.
Expand Down
3 changes: 1 addition & 2 deletions examples/2-encoders/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package main

import (
"github.com/mwm-io/gapi/handler"
gLog "github.com/mwm-io/gapi/log"
"github.com/mwm-io/gapi/middleware"
)

func init() {
middleware.Defaults = []handler.Middleware{
// We removed the default response writer to control response encoding for each handler
middleware.Log{Logger: gLog.Logger()},
middleware.Log{},
middleware.Recover{},
}
}
4 changes: 2 additions & 2 deletions examples/2-encoders/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/mwm-io/gapi/examples/2-encoders

go 1.18
go 1.19

require github.com/mwm-io/gapi v0.1.0
require github.com/mwm-io/gapi v0.2.0

require (
github.com/elnormous/contenttype v1.0.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/2-encoders/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/mwm-io/gapi v0.1.0 h1:KT4J6uwNX9uSZaeHcZzM2eR3zgSqGhyUY7UY4Tf9ZRc=
github.com/mwm-io/gapi v0.1.0/go.mod h1:kGkSeloZf2LJK1tqdgbUFK10MzBQVFjolpOCMnwEXRM=
github.com/mwm-io/gapi v0.2.0 h1:jhpCAHIZkuftPk5nIOISag2nC4Eq4FwjzwSHYIlSib4=
github.com/mwm-io/gapi v0.2.0/go.mod h1:gPTxM9Fhgn7m3+5angXq8+63tTToHbYb9JDTibJJYek=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
9 changes: 6 additions & 3 deletions examples/2-encoders/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"context"

gLog "github.com/mwm-io/gapi/log"
"github.com/mwm-io/gapi/server"

Expand All @@ -9,6 +11,7 @@ import (
)

func main() {
ctx := context.Background()
r := server.NewMux()

server.AddHandler(r, "GET", "/hello/json", hello.MakeJSONResponseHandler())
Expand All @@ -19,10 +22,10 @@ func main() {
server.AddHandler(r, "GET", "/error/xml", err.MakeXMLResponseHandler())
server.AddHandler(r, "GET", "/error/auto", err.MakeAutoResponseHandler())

gLog.Info("Starting http server")
gLog.Info(ctx, "Starting http server")
if errServe := server.ServeAndHandleShutdown(r); errServe != nil {
gLog.Emergency(errServe.Error())
gLog.Emergency(ctx, errServe.Error())
}

gLog.Info("Server stopped")
gLog.Info(ctx, "Server stopped")
}
4 changes: 2 additions & 2 deletions examples/3-params/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/mwm-io/gapi/examples/3-params

go 1.18
go 1.19

require github.com/mwm-io/gapi v0.1.0
require github.com/mwm-io/gapi v0.2.0

require (
github.com/elnormous/contenttype v1.0.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/3-params/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/mwm-io/gapi v0.1.0 h1:KT4J6uwNX9uSZaeHcZzM2eR3zgSqGhyUY7UY4Tf9ZRc=
github.com/mwm-io/gapi v0.1.0/go.mod h1:kGkSeloZf2LJK1tqdgbUFK10MzBQVFjolpOCMnwEXRM=
github.com/mwm-io/gapi v0.2.0 h1:jhpCAHIZkuftPk5nIOISag2nC4Eq4FwjzwSHYIlSib4=
github.com/mwm-io/gapi v0.2.0/go.mod h1:gPTxM9Fhgn7m3+5angXq8+63tTToHbYb9JDTibJJYek=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
9 changes: 6 additions & 3 deletions examples/3-params/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package main

import (
"context"

gLog "github.com/mwm-io/gapi/log"
"github.com/mwm-io/gapi/server"

"github.com/mwm-io/gapi/examples/3-params/internal"
)

func main() {
ctx := context.Background()
r := server.NewMux()

server.AddHandlerFactory(r, "POST", "/body", internal.NewBodyHandler)
Expand All @@ -16,10 +19,10 @@ func main() {
server.AddHandlerFactory(r, "GET", "/path-params/{first}/{second}", internal.NewPathParamsHandler)
server.AddHandlerFactory(r, "GET", "/query-params", internal.NewQueryParamsHandler)

gLog.Info("Starting http server")
gLog.Info(ctx, "Starting http server")
if err := server.ServeAndHandleShutdown(r); err != nil {
gLog.Emergency(err.Error())
gLog.Emergency(ctx, err.Error())
}

gLog.Info("Server stopped")
gLog.Info(ctx, "Server stopped")
}
4 changes: 2 additions & 2 deletions examples/4-doc-openapi/go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/mwm-io/gapi/examples/4-doc-openapi

go 1.18
go 1.19

require github.com/mwm-io/gapi v0.1.0
require github.com/mwm-io/gapi v0.2.0

require (
github.com/elnormous/contenttype v1.0.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions examples/4-doc-openapi/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
github.com/gorilla/schema v1.2.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/mwm-io/gapi v0.1.0 h1:KT4J6uwNX9uSZaeHcZzM2eR3zgSqGhyUY7UY4Tf9ZRc=
github.com/mwm-io/gapi v0.1.0/go.mod h1:kGkSeloZf2LJK1tqdgbUFK10MzBQVFjolpOCMnwEXRM=
github.com/mwm-io/gapi v0.2.0 h1:jhpCAHIZkuftPk5nIOISag2nC4Eq4FwjzwSHYIlSib4=
github.com/mwm-io/gapi v0.2.0/go.mod h1:gPTxM9Fhgn7m3+5angXq8+63tTToHbYb9JDTibJJYek=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
11 changes: 6 additions & 5 deletions examples/4-doc-openapi/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"log"
"context"

gLog "github.com/mwm-io/gapi/log"
"github.com/mwm-io/gapi/server"
Expand All @@ -12,6 +12,7 @@ import (
// This simple example show you how to make a CRUD for the users model.
// Each handler has a type.
func main() {
ctx := context.Background()
r := server.NewMux()

// All following handler are complete example to know how to make a handler with request-scope data
Expand All @@ -29,14 +30,14 @@ func main() {
// server.AddDocHandlers add handler to expose API documentation.
// Go to http://localhost:8080 to see the result
if err := server.AddDocHandlers(r); err != nil {
log.Printf("error while adding rapidoc %+v\n", err)
gLog.Error(ctx, err.Error())
}

gLog.Info("Starting http server")
gLog.Info(ctx, "Starting http server")

if err := server.ServeAndHandleShutdown(r); err != nil {
gLog.Emergency(err.Error())
gLog.Emergency(ctx, err.Error())
}

gLog.Info("Server stopped")
gLog.Info(ctx, "Server stopped")
}

0 comments on commit ec2659a

Please sign in to comment.