rpc

package
v0.0.0-...-baecc60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2022 License: MIT Imports: 19 Imported by: 3

Documentation

Index

Constants

View Source
const (
	PermRead  auth.Permission = "read" // default
	PermWrite auth.Permission = "write"
	PermSign  auth.Permission = "sign"  // Use wallet keys for signing
	PermAdmin auth.Permission = "admin" // Manage permissions
)

Variables

View Source
var AuthNewCmd = &cli.Command{
	Name:  "authnew",
	Usage: "创建一个新token",

	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "perm, p",
			Value: "read",
			Usage: "permission to assign to the token, one of: read, write, sign, admin",
		},
		cli.StringFlag{
			Name:        "secret, s",
			Value:       "123456",
			Usage:       "jwt 加密密码,请修改默认密码",
			Destination: &Cfg.APISecret,
		},
	},
	Action: func(cctx *cli.Context) error {

		perm := cctx.String("perm")
		idx := 0
		for i, p := range AllPermissions {
			if auth.Permission(perm) == p {
				idx = i + 1
			}
		}

		if idx == 0 {
			return fmt.Errorf("--perm flag has to be one of: %s", AllPermissions)
		}

		token, err := AuthNew(context.Background(), AllPermissions[:idx])
		if err != nil {
			return err
		}

		fmt.Println(string(token))
		return nil

	},
}
View Source
var Cfg = Config{APISecret: "123456", Token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.ae22SYWjZ_RJRRhfWDpVFzWThu_6EQ-iBgAn8vdrR-w"}
View Source
var DefaultPerms = []auth.Permission{}

Functions

func AuthHeader

func AuthHeader() http.Header

func AuthHeaderWtoken

func AuthHeaderWtoken(t string) http.Header

func AuthNew

func AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error)

func AuthVerify

func AuthVerify(ctx context.Context, token string) ([]auth.Permission, error)

func Generate

func Generate(path, pkg, outpkg, outfile string) error

func Generate2

func Generate2(path, pkg, outpkg, outfile string) error

func GetMothodInfo

func GetMothodInfo(path, pkg, outpkg, outfile string) (*meta, error)

func GetRpcClient

func GetRpcClient(t, url, name string, out interface{}) (func(), error)

func RegisterRpc

func RegisterRpc(v, out interface{}, name string) *jsonrpc.RPCServer

Types

type Config

type Config struct {
	Token     string
	APISecret string
}

type RpcService

type RpcService struct {
	Url           string
	V             interface{}
	Closer        func()
	Reaction_time time.Duration
}

type Visitor

type Visitor struct {
	Methods map[string]map[string]*methodMeta
	Include map[string][]string
}

func (*Visitor) Visit

func (v *Visitor) Visit(node ast.Node) ast.Visitor

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL