-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
likezhang
committed
Jul 9, 2022
1 parent
b5ec047
commit 075db1e
Showing
7 changed files
with
416 additions
and
23 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
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,25 @@ | ||
port: 9991 # for grpc service | ||
http: | ||
port: 9992 # for http service | ||
gateway: | ||
path: "/" | ||
static: | ||
path: "/web" | ||
filepath: "./static" | ||
# Another setting (you should modify the js code for backend api url) | ||
# gateway: | ||
# path: "/backend" | ||
# static: | ||
# path: "/" | ||
# filepath: "./static" | ||
swagger: | ||
path: "/swagger" | ||
filepath: "./swagger.json" | ||
client: | ||
address: "localhost:9993" # for grpc client url and port | ||
|
||
|
||
logging: | ||
level: debug # info | debug | ||
encoding: console # console | json | ||
output: "./log/default.log" |
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,32 @@ | ||
package main | ||
|
||
import ( | ||
_ "embed" | ||
|
||
"github.com/skema-dev/skema-go/config" | ||
"github.com/skema-dev/skema-go/grpcmux" | ||
"github.com/skema-dev/skema-go/logging" | ||
pb "github.com/skema-dev/skema-go/sample/api/skema/test" | ||
) | ||
|
||
//go:embed grpc.yaml | ||
var yamlConfig []byte | ||
|
||
func main() { | ||
grpcSrv := grpcmux.NewServerWithConfig( | ||
config.NewConfigWithString(string(yamlConfig)), | ||
) | ||
|
||
pb.RegisterTestServer(grpcSrv, NewServer()) | ||
|
||
// for http gateway only. | ||
ctx, mux, conn := grpcSrv.GetGatewayInfo() | ||
pb.RegisterTestHandlerClient(ctx, mux, pb.NewTestClient(conn)) | ||
|
||
//grpcSrv.EnableStaticContent("/", "./static") | ||
//grpcSrv.EnableStaticContent("/script", "./static/script") | ||
|
||
if err := grpcSrv.Serve(); err != nil { | ||
logging.Fatalf("Serve error %v", err.Error()) | ||
} | ||
} |
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,49 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
pb "github.com/skema-dev/skema-go/sample/api/skema/test" | ||
) | ||
|
||
type rpcTestServer struct { | ||
pb.UnimplementedTestServer | ||
} | ||
|
||
// NewServer: Create new grpc server instance | ||
func NewServer() pb.TestServer { | ||
svr := &rpcTestServer{ | ||
// init custom fileds | ||
} | ||
return svr | ||
} | ||
|
||
// Heathcheck | ||
func (s *rpcTestServer) Heathcheck( | ||
ctx context.Context, | ||
req *pb.HealthcheckRequest, | ||
) (rsp *pb.HealthcheckResponse, err error) { | ||
// implement business logic here ... | ||
// ... | ||
|
||
log.Printf("Received from Heathcheck request: %v", req) | ||
rsp = &pb.HealthcheckResponse{ | ||
Result: "health check ok", | ||
} | ||
|
||
return rsp, err | ||
} | ||
|
||
// Helloworld | ||
func (s *rpcTestServer) Helloworld(ctx context.Context, req *pb.HelloRequest) (rsp *pb.HelloReply, err error) { | ||
// implement business logic here ... | ||
// ... | ||
|
||
log.Printf("Received from Helloworld request: %v", req) | ||
rsp = &pb.HelloReply{ | ||
Msg: "Hello world", | ||
Code: "0", | ||
} | ||
return rsp, err | ||
} |
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,17 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Cache-control" content="no-cache"> | ||
<meta http-equiv="Expires" content="-1"> | ||
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin></script> | ||
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin></script> | ||
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> | ||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
</head> | ||
<body> | ||
<div id="main_container"></div> | ||
<script src="/web/script/main.js" type="text/babel"></script> | ||
</body> | ||
</html> |
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,92 @@ | ||
'use strict'; | ||
|
||
class Lesson extends React.Component { | ||
constructor(props) { | ||
console.log(props) | ||
super(props); | ||
this.state = { | ||
lessonId: props.lessonId, | ||
name: props.name, | ||
description: props.description | ||
} | ||
} | ||
|
||
loadLession() { | ||
let lessons = new Map() | ||
lessons.set("lesson1", <Lesson1 />) | ||
lessons.set("lesson2", <Lesson2 />) | ||
lessons.set("lesson3", <Lesson3 />) | ||
root.render(lessons.get(this.state.name)); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<button onClick={() => this.loadLession() }> | ||
{ this.state.name } | ||
</button> | ||
<br/> | ||
{ this.state.description } | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
class ApiList extends React.Component { | ||
constructor(props) { | ||
console.log(props) | ||
super(props); | ||
this.state = { | ||
result: "" | ||
} | ||
this.healthCheck = this.healthCheck.bind(this); | ||
this.helloWorld = this.helloWorld.bind(this); | ||
} | ||
|
||
healthCheck() { | ||
axios | ||
.get('/api/healthcheck') | ||
.then(response => { | ||
this.setState({result: "healthcheck: " + response.data.result}); | ||
}) | ||
.catch(function (error) { // 请求失败处理 | ||
console.log(error); | ||
}); | ||
} | ||
|
||
helloWorld() { | ||
axios | ||
.post('/api/helloworld') | ||
.then(response => { | ||
this.setState({result: "helloworld:" + response.data.msg}); | ||
}) | ||
.catch(function (error) { // 请求失败处理 | ||
console.log(error); | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div style={{ textAlign: "center" }}> | ||
<b>API List</b> | ||
<hr/> | ||
<button onClick={this.healthCheck}> | ||
Call HealthCheck | ||
</button> | ||
<br/> | ||
<br/> | ||
<button onClick={this.helloWorld}> | ||
Call HelloWorld | ||
</button> | ||
<br/> | ||
<br/> | ||
{ this.state.result } | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
|
||
const domContainer1 = document.querySelector('#main_container'); | ||
const root = ReactDOM.createRoot(domContainer1); | ||
root.render(<ApiList />); |
Oops, something went wrong.