Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@iawia002
Copy link

@iawia002 iawia002 commented Nov 19, 2020

What this PR does / why we need it:

Add a new builder to support serve RPC style APIs:

POST /?Action=GetUserByID&Version=2018-01-01

The default builder is still RESTful builder, here is an example to use RPC builder:

var echo = definition.RPCDescriptor{
	Description: "Echo API",
	Middlewares: []definition.Middleware{reqlog.Default()},
	Consumes:    []string{definition.MIMEAll},
	Produces:    []string{definition.MIMEJSON},
	Actions: []definition.RPCAction{
		{
			Name:    "Echo",
			Version: "2020-10-10",
			Function: func(ctx context.Context, msg string) (string, error) {
				return msg, nil
			},
			Parameters: []definition.Parameter{
				{
					Source:      definition.Query,
					Name:        "msg",
					Description: "Corresponding to the second parameter",
				},
			},
			Results: definition.DataErrorResults(""),
		},
		{
			Name:    "Echo1",
			Version: "2020-10-10",
			Function: func(ctx context.Context, msg string) (string, error) {
				return msg, nil
			},
			Parameters: []definition.Parameter{
				{
					Source:      definition.Query,
					Name:        "msg",
					Description: "Corresponding to the second parameter",
				},
			},
			Results: definition.DataErrorResults(""),
		},
	},
}

func main() {
	cmd := config.NewDefaultNirvanaCommand()
	conf := nirvana.NewDefaultConfig()
	conf.Configure(
		nirvana.APIStyle(builder.APIStyleRPC),
		nirvana.Descriptor(echo, echo2),
	)
	if err := cmd.ExecuteWithConfig(conf); err != nil {
		log.Fatal(err)
	}
}
INFO  1119-18:25:59.051+08 config.go:309 | Listening on :8080
INFO  1119-18:25:59.052+08 builder.go:180 | Path: /?Version=2020-10-10&Action=Echo, Consumes: [*/*], Produces: [application/json]
INFO  1119-18:25:59.052+08 builder.go:180 | Path: /?Version=2020-10-10&Action=Echo1, Consumes: [*/*], Produces: [application/json]

And for generating API documentation for RPC style APIs, you need to add a style tag to the descriptors file:

// +nirvana:api=descriptors:"Descriptor" style:"rpc"

Screen Shot 2020-11-19 at 18 41 33

Which issue(s) this PR is related to (optional, link to 3rd issue(s)):

Fixes #

Reference to #

Special notes for your reviewer:

/cc @xpofei

Release note:

NONE

@caicloud-bot caicloud-bot requested a review from xpofei November 19, 2020 07:04
@caicloud-bot caicloud-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. caicloud-cla: yes Indicates the PR's author has not signed the Caicloud CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 19, 2020
@iawia002 iawia002 force-pushed the rpc-builder branch 2 times, most recently from 89b2d78 to 8f89f9e Compare November 19, 2020 08:07
@iawia002
Copy link
Author

@xpofei All comments addressed, PTAL

@iawia002 iawia002 changed the title WIP: feat(*): support RPC style feat(*): support RPC style Nov 20, 2020
@caicloud-bot caicloud-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 20, 2020
@xpofei
Copy link
Contributor

xpofei commented Nov 20, 2020

/lgtm

@caicloud-bot caicloud-bot added the lgtm Indicates that a PR is ready to be merged. label Nov 20, 2020
@iawia002
Copy link
Author

/approve
/cherrypick release-0.3

@caicloud-bot
Copy link
Contributor

@iawia002: once the present PR merges, I will cherry-pick it on top of release-0.3 in a new PR and assign it to you.

In response to this:

/approve
/cherrypick release-0.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@caicloud-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: iawia002, xpofei

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@caicloud-bot caicloud-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 20, 2020
@caicloud-bot caicloud-bot merged commit 19cadf9 into caicloud:master Nov 20, 2020
@caicloud-bot
Copy link
Contributor

@iawia002: new pull request created: #388

In response to this:

/approve
/cherrypick release-0.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. caicloud-cla: yes Indicates the PR's author has not signed the Caicloud CLA. lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants