-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update dependent redoc js for swagger ui (gogf#3217)
- Loading branch information
Showing
7 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ package grpcx | |
|
||
import ( | ||
"context" | ||
|
||
"google.golang.org/grpc" | ||
|
||
"github.com/gogf/gf/v2/frame/g" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
server: | ||
address: ":8199" | ||
openapiPath: "/api.json" | ||
swaggerPath: "/swagger" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/gogf/gf/v2/frame/g" | ||
"github.com/gogf/gf/v2/net/ghttp" | ||
) | ||
|
||
// HelloReq hello request | ||
type HelloReq struct { | ||
g.Meta `path:"/hello" method:"get" sort:"1"` | ||
Name string `v:"required" dc:"Your name"` | ||
} | ||
|
||
// HelloRes hello response | ||
type HelloRes struct { | ||
Reply string `dc:"Reply content"` | ||
} | ||
|
||
// Hello Controller | ||
type Hello struct{} | ||
|
||
// Say function | ||
func (Hello) Say(ctx context.Context, req *HelloReq) (res *HelloRes, err error) { | ||
g.Log().Debugf(ctx, `receive say: %+v`, req) | ||
res = &HelloRes{ | ||
Reply: fmt.Sprintf(`Hi %s`, req.Name), | ||
} | ||
return | ||
} | ||
|
||
const ( | ||
MySwaggerUITemplate = ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="description" content="SwaggerUI"/> | ||
<title>SwaggerUI</title> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.10.5/swagger-ui.min.css" /> | ||
</head> | ||
<body> | ||
<div id="swagger-ui"></div> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/5.10.5/swagger-ui-bundle.js" crossorigin></script> | ||
<script> | ||
window.onload = () => { | ||
window.ui = SwaggerUIBundle({ | ||
url: '{SwaggerUIDocUrl}', | ||
dom_id: '#swagger-ui', | ||
}); | ||
}; | ||
</script> | ||
</body> | ||
</html> | ||
` | ||
) | ||
|
||
func main() { | ||
s := g.Server() | ||
s.Use(ghttp.MiddlewareHandlerResponse) | ||
s.Group("/", func(group *ghttp.RouterGroup) { | ||
group.Bind( | ||
new(Hello), | ||
) | ||
}) | ||
s.SetSwaggerUITemplate(MySwaggerUITemplate) | ||
s.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters