Skip to content

Commit a86a3a3

Browse files
committed
Add gin
1 parent 48f8b7b commit a86a3a3

File tree

15 files changed

+831
-555
lines changed

15 files changed

+831
-555
lines changed

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,14 @@ import "github.com/core-go/core"
1212
```
1313

1414
### Microservice Architect
15-
![Microservice Architect](https://camo.githubusercontent.com/cf46a1780520d3612f1d81b219b56a14428fc24bb4ae9f4eede169aa9c58bee8/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a764b6565504f5f5543373369377466796d536d594e412e706e67)
15+
![Microservice Architect](https://cdn-images-1.medium.com/max/800/1*vKeePO_UC73i7tfymSmYNA.png)
1616

1717
### A typical micro service
1818
When you zoom one micro service, the flow is as below
19-
![A typical micro service](https://camo.githubusercontent.com/581033268b9152e7ea8881904f533a51a29eeb3a63e8d6478540668c6e422ce3/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a64396b79656b416251594278482d4336773338585a512e706e67)
20-
21-
### Cross-cutting concerns
22-
We provide many libraries to minimize effort for cross-cutting concerns
23-
![cross-cutting concerns](https://camo.githubusercontent.com/0416e6d9aa090b3b42901b4dd22b19c8962abe6c589988b1e97dea97b63a278d/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a7930383854344e6f4a4e724c397371724b65537971772e706e67)
19+
![cross-cutting concerns](https://cdn-images-1.medium.com/max/800/1*y088T4NoJNrL9sqrKeSyqw.png)
2420

2521
#### Health
26-
![health](https://camo.githubusercontent.com/49287a63a0e1c52818c4321650b3f8cf2348d5f50108aed820cd6441fbb2574d/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a6746457a416b7674666e51575665463265644b7767512e706e67)
22+
![health](https://cdn-images-1.medium.com/max/800/1*wiWnkgzUoSgJT9QUXfzI8A.png)
2723

2824
#### Email
29-
![Email](https://camo.githubusercontent.com/0fcd0826eea9b9883077ac1674e45c4eafa17e7abb02f8d2659fb30bc2b084e5/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f3830302f312a2d6c486a7872355a4d6b4b634c6961746776364731672e706e67)
25+
![Email](https://cdn-images-1.medium.com/max/800/1*-lHjxr5ZMkKcLiatgv6G1g.png)

echo/handler.go

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
Update = "update"
1515
Patch = "patch"
1616
)
17+
1718
func IsPatch(ctx context.Context) bool {
1819
m := ctx.Value(Method)
1920
if m != nil && m.(string) == Patch {
@@ -55,6 +56,7 @@ type PatchHandler struct {
5556
ResourceType string
5657
Activity string
5758
}
59+
5860
func (h *PatchHandler) Patch(ctx echo.Context) error {
5961
r := ctx.Request()
6062
r = r.WithContext(context.WithValue(r.Context(), Method, Patch))
@@ -362,37 +364,7 @@ func Respond(ctx echo.Context, code int, result interface{}, err error, logError
362364
return Succeed(ctx, code, result, writeLog, resource, action)
363365
}
364366
}
365-
/*
366-
func Return222(ctx echo.Context, code int, result sv.ResultInfo, status sv.StatusConfig, err error, logError func(context.Context, string, ...map[string]interface{}), writeLog func(context.Context, string, string, bool, string) error, options ...string) {
367-
var resource, action string
368-
if len(options) > 0 && len(options[0]) > 0 {
369-
resource = options[0]
370-
}
371-
if len(options) > 1 && len(options[1]) > 0 {
372-
action = options[1]
373-
}
374-
if err != nil {
375-
RespondAndLog(ctx, http.StatusInternalServerError, sv.InternalServerError, err, logError, writeLog, resource, action)
376-
} else {
377-
if code == http.StatusCreated {
378-
if result.Status == status.DuplicateKey {
379-
Succeed(ctx, http.StatusConflict, result, writeLog, resource, action)
380-
} else {
381-
Succeed(ctx, code, result, writeLog, resource, action)
382-
}
383-
} else {
384-
if result.Status == status.NotFound {
385-
Succeed(ctx, http.StatusNotFound, result, writeLog, resource, action)
386-
} else if result.Status == status.VersionError {
387-
Succeed(ctx, http.StatusConflict, result, writeLog, resource, action)
388-
} else {
389-
Succeed(ctx, code, result, writeLog, resource, action)
390-
}
391-
}
392-
}
393-
}
394-
*/
395-
func Result(ctx echo.Context, code int, result interface{}, err error, logError func(context.Context, string, ...map[string]interface{}), opts...interface{}) error {
367+
func Result(ctx echo.Context, code int, result interface{}, err error, logError func(context.Context, string, ...map[string]interface{}), opts ...interface{}) error {
396368
if err != nil {
397369
if len(opts) > 0 && opts[0] != nil {
398370
b, er2 := json.Marshal(opts[0])

echo/v3/handler.go

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const (
1414
Update = "update"
1515
Patch = "patch"
1616
)
17+
1718
func CreatePatchAndParams(modelType reflect.Type, logError func(context.Context, string, ...map[string]interface{}), patch func(context.Context, map[string]interface{}) (int64, error), validate func(context.Context, interface{}) ([]sv.ErrorMessage, error), build func(context.Context, interface{}) (interface{}, error), action *sv.ActionConfig, options ...func(context.Context, string, string, bool, string) error) (*PatchHandler, *sv.Params) {
1819
var writeLog func(context.Context, string, string, bool, string) error
1920
if len(options) > 0 {
@@ -48,6 +49,7 @@ type PatchHandler struct {
4849
ResourceType string
4950
Activity string
5051
}
52+
5153
func (h *PatchHandler) Patch(ctx echo.Context) error {
5254
r := ctx.Request()
5355
r = r.WithContext(context.WithValue(r.Context(), Method, Patch))
@@ -355,37 +357,7 @@ func Respond(ctx echo.Context, code int, result interface{}, err error, logError
355357
return Succeed(ctx, code, result, writeLog, resource, action)
356358
}
357359
}
358-
/*
359-
func Return222(ctx echo.Context, code int, result sv.ResultInfo, status sv.StatusConfig, err error, logError func(context.Context, string, ...map[string]interface{}), writeLog func(context.Context, string, string, bool, string) error, options ...string) {
360-
var resource, action string
361-
if len(options) > 0 && len(options[0]) > 0 {
362-
resource = options[0]
363-
}
364-
if len(options) > 1 && len(options[1]) > 0 {
365-
action = options[1]
366-
}
367-
if err != nil {
368-
RespondAndLog(ctx, http.StatusInternalServerError, sv.InternalServerError, err, logError, writeLog, resource, action)
369-
} else {
370-
if code == http.StatusCreated {
371-
if result.Status == status.DuplicateKey {
372-
Succeed(ctx, http.StatusConflict, result, writeLog, resource, action)
373-
} else {
374-
Succeed(ctx, code, result, writeLog, resource, action)
375-
}
376-
} else {
377-
if result.Status == status.NotFound {
378-
Succeed(ctx, http.StatusNotFound, result, writeLog, resource, action)
379-
} else if result.Status == status.VersionError {
380-
Succeed(ctx, http.StatusConflict, result, writeLog, resource, action)
381-
} else {
382-
Succeed(ctx, code, result, writeLog, resource, action)
383-
}
384-
}
385-
}
386-
}
387-
*/
388-
func Result(ctx echo.Context, code int, result interface{}, err error, logError func(context.Context, string, ...map[string]interface{}), opts...interface{}) error {
360+
func Result(ctx echo.Context, code int, result interface{}, err error, logError func(context.Context, string, ...map[string]interface{}), opts ...interface{}) error {
389361
if err != nil {
390362
if len(opts) > 0 && opts[0] != nil {
391363
b, er2 := json.Marshal(opts[0])

0 commit comments

Comments
 (0)