verify

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

README

library/net/http/blademaster/middleware/verify

项目简介

blademaster 的 verify middleware,主要用于设置路由的校验策略

编译环境

  • 请只用 Golang v1.10.x 以上版本编译执行

依赖包

  • No other dependency

Documentation

Overview

Example

This example create a identify middleware instance and attach to several path, it will validate request by specified policy and put extra information into context. e.g., `mid`. It provides additional handler functions to provide the identification for your business handler.

package main

import (
	"fmt"
	"time"

	bm "go-common/library/net/http/blademaster"
	"go-common/library/net/http/blademaster/middleware/verify"
	"go-common/library/net/metadata"

	xtime "go-common/library/time"
)

func main() {
	idt := verify.New(&verify.Config{
		OpenServiceHost: "http://uat-open.bilibili.co",
		HTTPClient: &bm.ClientConfig{
			App: &bm.App{
				Key:    "53e2fa226f5ad348",
				Secret: "3cf6bd1b0ff671021da5f424fea4b04a",
			},
			Dial:      xtime.Duration(time.Second),
			Timeout:   xtime.Duration(time.Second),
			KeepAlive: xtime.Duration(time.Second * 10),
		},
	})

	e := bm.Default()
	// mark `/verify` path as Verify policy
	e.GET("/verify", idt.Verify, func(c *bm.Context) {
		c.JSON("pass", nil)
	})
	// mark `/verify` path as VerifyUser policy
	e.GET("/verifyUser", idt.VerifyUser, func(c *bm.Context) {
		mid := metadata.Int64(c, metadata.Mid)
		c.JSON(fmt.Sprintf("%d", mid), nil)
	})
	e.Run(":18080")
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sign

func Sign(params url.Values, appkey string, secret string, lower bool) string

Sign is used to sign form params by given condition.

Types

type Config

type Config struct {
	OpenServiceHost string
	HTTPClient      *bm.ClientConfig
}

Config is the verify config model.

type Verify

type Verify struct {
	// contains filtered or unexported fields
}

Verify is is the verify model.

func New

func New(conf *Config) *Verify

New will create a verify middleware by given config. panic on conf is nil.

func (*Verify) Verify

func (v *Verify) Verify(ctx *bm.Context)

Verify will inject into handler func as verify required

func (*Verify) VerifyUser

func (v *Verify) VerifyUser(ctx *bm.Context)

VerifyUser is used to mark path as verify and mid required.

Jump to

Keyboard shortcuts

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