app_context

package
v0.0.0-...-c2450c0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AdminUserService service.AdminUserService
View Source
var AuthRoleService service.AuthRoleService
View Source
var Context inject.Graph

Typically an application will have exactly one object graph, and you will create it and use it within a main function:

View Source
var ErrorFilter = easy_mvc.HttpErrorHandle{
	Func: func(err interface{}, w http.ResponseWriter, r *http.Request) {
		if err != nil {
			debug.PrintStack()
			switch err.(type) {
			case error:
				println(err.(error).Error())
				var vo = vo.ResultVO{}.NewError(-1, err.(error).Error()+string(debug.Stack()))
				var b, _ = json.Marshal(vo)
				w.Write(b)
			default:
				var errdata = fmt.Sprint(err) + string(debug.Stack())
				println(errdata)
				var vo = vo.ResultVO{}.NewError(-1, errdata)
				var b, _ = json.Marshal(vo)
				w.Write(b)
			}
		}
	},
	Name: "ErrorFilter",
}
View Source
var KVService service.KVService
View Source
var LogChain = easy_mvc.HttpChan{
	Name: "LogChain",
	Func: func(path string, w http.ResponseWriter, r *http.Request) bool {
		var reqInfo = "http " + r.Method + "  => " + path + " "
		reqInfo += ":arg=" + fmt.Sprint(r.Form)

		log.Println(reqInfo)
		return false
	},
}

日志链

View Source
var LoginFilter = easy_mvc.HttpChan{
	Name: "LoginFilter:" + "/api/user/",
	Func: func(path string, w http.ResponseWriter, r *http.Request) bool {
		if strings.Contains(path, "/api/user/") {
			//拦截"/api/user"的接口
			var e = utils.CheckLoginToken(&r.Form, nil)
			if e != nil {
				var r = vo.ResultVO{}.NewError(-6, e.Error())
				var b, _ = json.Marshal(r)
				w.Write(b)
				return true
			}
		}
		return false
	},
}

登录过滤

View Source
var LoginFilterAdmin = easy_mvc.HttpChan{
	Name: "LoginFilter:" + "/admin/",
	Func: func(path string, w http.ResponseWriter, r *http.Request) bool {
		if strings.Contains(path, "/admin/user/") {
			//过期检查
			var outOfTime = 4 * time.Hour
			var e = utils.CheckLoginToken(&r.Form, &outOfTime)
			if e != nil {
				var r = vo.ResultVO{}.NewError(-6, e.Error())
				var b, _ = json.Marshal(r)
				w.Write(b)
				return true
			}
			//权限检查
			var res = r.Form.Get(utils.Key_res)
			var hash = utils.CountHash4(r.URL.Path)
			if strings.Contains(res, hash) {
				println("done")
			} else {
				var r = vo.ResultVO{}.NewError(-6, "当前资源无权限访问!")
				var b, _ = json.Marshal(r)
				w.Write(b)
				return true
			}

		}
		return false
	},
}

后台登录

View Source
var MallClassService service.MallClassService
View Source
var MallCoverImageService service.MallCoverImageService
View Source
var MallOrderService service.MallOrderService
View Source
var MallSkuService service.MallSkuService
View Source
var MallSpecificationService service.MallSpecificationService
View Source
var PayService service.PayService
View Source
var PropertyService service.PropertyService
View Source
var RegionService service.RegionService
View Source
var ResultFilter = easy_mvc.HttpResultHandle{
	Func: func(result *interface{}, w http.ResponseWriter, r *http.Request) bool {
		if *result != nil {
			var rv = reflect.TypeOf(*result)
			if strings.Contains(rv.String(), "error") || strings.Contains(rv.String(), "Error") {
				var msg = (*result).(error).Error()
				var v = vo.ResultVO{}.NewError(-1, msg)
				var b, _ = json.Marshal(v)
				w.Write(b)
				return true
			} else {
				var b, _ = json.Marshal(r)
				w.Write(b)
			}
		}
		return false
	},
	Name: "ResultFilter",
}
View Source
var RpcServiceBeanTable = []easyrpc_discovery.RpcServiceBean{}
View Source
var StoreService service.StoreService

只需要在这里注册服务

View Source
var UrlArray = []vo.AuthResourceVO{}

map[url]hash

View Source
var UserService service.UserService

Functions

func ReflectRegisterService

func ReflectRegisterService(server interface{})

Types

type AppConfig

type AppConfig struct {
	PlatformName  string `json:"platform_name"` //平台中文名称
	SwaggerEnable bool
	ClientName    string `json:"client_name"`
	Host          string `json:"host"`
	Port          int    `json:"port"`
	ConsulUrl     string `json:"consul_url"`
	FastDFSUrl    string `json:"fast_dfs_url"`
}

type CustomHttpChan

type CustomHttpChan struct {
	easy_mvc.HttpChan
}

Jump to

Keyboard shortcuts

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