Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Iris to version 12 #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/web/helloworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func (c *Controller) Get(at struct {
at.GetMapping `value:"/"`
at.Operation `id:"helloWorld" description:"This is hello world API"`
at.Produces `values:"text/plain"`
Responses struct {
Responses struct {
StatusOK struct {
at.Response `code:"200" description:"response status OK"`
at.Schema `type:"string" description:"returns hello world message"`
at.Schema `type:"string" description:"returns hello world message"`
}
}
}) string {
Expand Down
10 changes: 8 additions & 2 deletions examples/web/httpserver/statik/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ func newStaticController() *controller {
}

// UI serve static resource via context StaticResource method
func (c *controller) UI(at struct{ at.GetMapping `value:"/ui/*"`; at.FileServer `value:"/ui"` }, ctx context.Context) {
func (c *controller) UI(at struct {
at.GetMapping `value:"/ui/*"`
at.FileServer `value:"/ui"`
}, ctx context.Context) {
return
}

// UI serve static resource via context StaticResource method
func (c *controller) UIIndex(at struct{ at.GetMapping `value:"/ui"`; at.FileServer `value:"/ui"` }, ctx context.Context) {
func (c *controller) UIIndex(at struct {
at.GetMapping `value:"/ui"`
at.FileServer `value:"/ui"`
}, ctx context.Context) {
return
}

Expand Down
2 changes: 1 addition & 1 deletion examples/web/httpserver/statik/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ func TestController(t *testing.T) {
func TestRunMain(t *testing.T) {
go main()
time.Sleep(100 * time.Millisecond)
}
}
1 change: 0 additions & 1 deletion examples/web/jaeger/publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
type Controller struct {
// at.RestController or at.RestController must be embedded here
at.RestController

}

// Get GET /publisher/{publisher}
Expand Down
8 changes: 4 additions & 4 deletions examples/web/jwt/controller/foo.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type fooRequestParam struct {
type fooResponse struct {
at.ResponseBody
AppNameVersion string `json:"appNameVersion"`
Greeting string `json:"greeting"`
Age int `json:"age"`
Greeting string `json:"greeting"`
Age int `json:"age"`
}

type fooController struct {
Expand Down Expand Up @@ -83,8 +83,8 @@ func (c *fooController) Get(request *fooRequestParam) (response model.Response,
response = new(model.BaseResponse)
response.SetData(&fooResponse{
AppNameVersion: c.AppNameVersion,
Greeting: "Hello, " + request.Name,
Age: request.Age})
Greeting: "Hello, " + request.Name,
Age: request.Age})

return
}
Expand Down
2 changes: 0 additions & 2 deletions examples/web/jwt/service/counthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ func (h *CountHandler) OnDisconnect() {
log.Debugf("Connection with ID: %v has been disconnected!", h.connection.ID())
}


// OnPing is the websocket ping handler
func (h *CountHandler) OnPing() {
log.Debugf("Connection with ID: %v has been pinged!", h.connection.ID())
}


// OnPong is the websocket pong handler
func (h *CountHandler) OnPong() {
log.Debugf("Connection with ID: %v has been ponged!", h.connection.ID())
Expand Down
5 changes: 1 addition & 4 deletions examples/web/jwt/service/statushandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ func (h *StatusHandler) OnDisconnect() {
log.Debugf("Connection with ID: %v has been disconnected!", h.connection.ID())
}



// OnPing is the websocket ping handler
func (h *StatusHandler) OnPing() {
log.Debugf("Connection with ID: %v has been pinged!", h.connection.ID())
}


// OnPong is the websocket pong handler
func (h *StatusHandler) OnPong() {
log.Debugf("Connection with ID: %v has been ponged!", h.connection.ID())
}
}
10 changes: 3 additions & 7 deletions examples/web/middleware/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func newUserController() *UserController {
}

type User struct {
ID int `json:"id"`
ID int `json:"id"`
Username string `json:"username"`
Password string `json:"password"`
}
Expand All @@ -34,7 +34,7 @@ type UserResponse struct {
}

// GetUser
func (c *UserController) GetUser(at struct{
func (c *UserController) GetUser(at struct {
at.GetMapping `value:"/{id}"`
}, id int) (response *UserResponse) {
response = new(UserResponse)
Expand All @@ -45,15 +45,11 @@ func (c *UserController) GetUser(at struct{
}

// GetUser
func (c *UserController) DeleteUser(at struct{
func (c *UserController) DeleteUser(at struct {
at.DeleteMapping `value:"/{id}"`
}, id int) (response *UserResponse) {
response = new(UserResponse)
response.SetCode(http.StatusOK)
response.SetMessage("Success")
return
}




1 change: 0 additions & 1 deletion examples/web/middleware/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func TestMiddleware(t *testing.T) {
Body().Contains("123456")
})


t.Run("should delete user", func(t *testing.T) {
testApp.Delete("/user/123456").
Expect().Status(http.StatusOK)
Expand Down
5 changes: 3 additions & 2 deletions examples/web/middleware/logging/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ func init() {

// Logging is the middleware handler,it support dependency injection, method annotation
// middleware handler can be annotated to specific purpose or general purpose
func (m *loggingMiddleware) Logging( at struct{at.MiddlewareHandler `value:"/" `}, ctx context.Context) {
func (m *loggingMiddleware) Logging(at struct {
at.MiddlewareHandler `value:"/" `
}, ctx context.Context) {

log.Infof("[logging middleware] %v", ctx.GetCurrentRoute())

// call ctx.Next() if you want to continue, otherwise do not call it
ctx.Next()
return
}

4 changes: 2 additions & 2 deletions examples/web/middleware/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import (
func main() {
// create new web application and run it
web.NewApplication().
SetProperty(app.ProfilesInclude, web.Profile, actuator.Profile,).
SetProperty(app.ProfilesInclude, web.Profile, actuator.Profile).
Run()
}
}
28 changes: 21 additions & 7 deletions examples/web/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func newUserController() *UserController {
}

// Create
func (c *UserController) CreateUser(at struct{ at.PostMapping `value:"/"` },
func (c *UserController) CreateUser(at struct {
at.PostMapping `value:"/"`
},
request *UserRequest) (response *UserResponse, err error) {

// response
Expand All @@ -88,7 +90,9 @@ func (c *UserController) CreateUser(at struct{ at.PostMapping `value:"/"` },
}

// Get
func (c *UserController) GetUserByPathVariable(at struct{ at.GetMapping `value:"/{id:int}/and/{name}"` },
func (c *UserController) GetUserByPathVariable(at struct {
at.GetMapping `value:"/{id:int}/and/{name}"`
},
id int, name string) (response *UserResponse, err error) {

// response
Expand All @@ -105,7 +109,9 @@ func (c *UserController) GetUserByPathVariable(at struct{ at.GetMapping `value:"
}

// Patch
func (c *UserController) Patch(at struct{ at.PatchMapping `value:"/{id}"` },
func (c *UserController) Patch(at struct {
at.PatchMapping `value:"/{id}"`
},
id int) (response *UserResponse, err error) {

// response
Expand All @@ -114,15 +120,19 @@ func (c *UserController) Patch(at struct{ at.PatchMapping `value:"/{id}"` },
}

// Delete
func (c *UserController) DeleteUser(at struct{ at.DeleteMapping `value:"/{id:int}"` },
func (c *UserController) DeleteUser(at struct {
at.DeleteMapping `value:"/{id:int}"`
},
id int) (response *UserResponse, err error) {
// response
response = new(UserResponse)
return
}

// List
func (c *UserController) ListUser(at struct{ at.GetMapping `value:"/"` }) (response *UserResponse, err error) {
func (c *UserController) ListUser(at struct {
at.GetMapping `value:"/"`
}) (response *UserResponse, err error) {
// response
response = new(UserResponse)
user := new(User)
Expand Down Expand Up @@ -155,13 +165,17 @@ func newOrgController() *orgController {

// GetOfficialSite
// at.Method is a annotations to define request mapping for http method GET
func (c *orgController) GetOfficialSite(at struct{ at.GetMapping `value:"/official-site"` }) string {
func (c *orgController) GetOfficialSite(at struct {
at.GetMapping `value:"/official-site"`
}) string {
return "https://hidevops.io"
}

// GetWithPathParamIdAndName
// at.GetMapping is an annotation to define request mapping for http method GET,
func (c *orgController) GetWithPathVariable(at struct{ at.GetMapping `value:"/{id}/and/{name}"` },
func (c *orgController) GetWithPathVariable(at struct {
at.GetMapping `value:"/{id}/and/{name}"`
},
id int, name string) string {

return fmt.Sprintf("https://hidevops.io/%v/%v", id, name)
Expand Down
11 changes: 5 additions & 6 deletions examples/web/swagger/greeting-server/controller/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ func newHelloController() *controller {
type HelloQueryParam struct {
at.RequestParams
at.Schema
Name string `schema:"defaults to World if not given"`
Name string `schema:"defaults to World if not given"`
}

// Hello
func (c *controller) Hello(at struct {
at.GetMapping `value:"/hello"`
at.Operation `id:"hello" description:"This is the Greeting api for demo"`
at.Produces `values:"text/plain"`
Parameters struct {
Name struct{
Parameters struct {
Name struct {
at.Parameter `type:"string" name:"name" in:"query" description:"defaults to World if not given" `
}
}
Expand All @@ -53,14 +53,13 @@ func (c *controller) Hello(at struct {
return
}


// Hey
func (c *controller) Hey(at struct {
at.GetMapping `value:"/hey"`
at.Operation `id:"hey" description:"This is the another Greeting api for demo"`
at.Produces `values:"text/plain"`
Parameters struct {
Name struct{
Parameters struct {
Name struct {
at.Parameter `type:"string" name:"name" in:"query" description:"defaults to HiBoot if not given" `
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ func TestController(t *testing.T) {
})

}

12 changes: 6 additions & 6 deletions examples/web/swagger/greeting-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
version = "1.0.3"
version = "1.0.3"
basePath = "/api/v1/greeting-server"
)

Expand All @@ -24,11 +24,11 @@ func init() {
ContactURL("https://hidevops.io").
Title("HiBoot Swagger Demo Application - Greeting Server").
Description("Greeting Server is an application that demonstrate the usage of Swagger Annotations"),
// alternatively, you can set below properties by using SetProperty() in main, config/application.yml or program arguments to take advantage of HiBoot DI
//Version(version).
//Schemes("http", "https").
//Host("localhost:8080").
//BasePath(basePath),
// alternatively, you can set below properties by using SetProperty() in main, config/application.yml or program arguments to take advantage of HiBoot DI
//Version(version).
//Schemes("http", "https").
//Host("localhost:8080").
//BasePath(basePath),
)
}

Expand Down
1 change: 0 additions & 1 deletion examples/web/swagger/greeting-server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ func TestRunMain(t *testing.T) {
time.Sleep(1)
go main()
}

Loading