当前位置: 首页>>代码示例>>Golang>>正文


Golang interfaces.Context类代码示例

本文整理汇总了Golang中github.com/opesun/nocrud/frame/interfaces.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: selectHook

func selectHook(ctx iface.Context, hookName string) *hook {
	return &hook{
		ctx,
		ctx.Conducting().Hooks().Select(hookName),
		hookName,
	}
}
开发者ID:crufter,项目名称:nocrud,代码行数:7,代码来源:builtins.go

示例2: Init

func (c *C) Init(ctx iface.Context) {
	c.Basics.Hooks = ctx.Conducting().Hooks()
	c.Basics.Db = ctx.Db()
	c.fileSys = ctx.FileSys()
	c.opt = ctx.Options().Document().All().(map[string]interface{})
	c.fileBiz = map[string][]iface.ReadableFile{}
}
开发者ID:Laller,项目名称:nocrud,代码行数:7,代码来源:file.go

示例3: Init

func (e *Entries) Init(ctx iface.Context) {
	e.db = ctx.Db()
	e.userId = ctx.User().Id()
	e.userIsProfessional = isProfessional(ctx.User())
	e.optDoc = ctx.Options().Document()
	e.timeTableColl = "timeTables"
	e.intervalColl = "intervals"
}
开发者ID:crufter,项目名称:nocrud,代码行数:8,代码来源:meeting.go

示例4: getList

func getList(ctx iface.Context, noun string, params ...interface{}) []interface{} {
	nouns, ok := ctx.Options().Document().GetM("nouns")
	if !ok {
		panic("Can't find nouns.")
	}
	inp := convert.ListToMap(params...)
	hl, err := highlev.New(ctx.Conducting().Hooks(), "/"+noun, nouns, inp)
	if err != nil {
		panic(err)
	}
	deflev_i, _ := ctx.Options().Document().Get("default_level")
	deflev, _ := numcon.Int(deflev_i)
	ret, err := hl.Run(ctx.Db(), ctx.User(), deflev)
	if err != nil {
		panic(err)
	}
	return ret
}
开发者ID:Laller,项目名称:nocrud,代码行数:18,代码来源:builtins.go

示例5: pager

func pager(ctx iface.Context, pagestr string, count, limit int) []paging.Pelem {
	if len(pagestr) == 0 {
		pagestr = "1"
	}
	if limit == 0 {
		return nil
	}
	p := ctx.NonPortable().Resource() + "?" + ctx.NonPortable().RawParams()
	page, err := strconv.Atoi(pagestr)
	if err != nil {
		return nil // Not blowing up here.
	}
	if page == 0 {
		return nil
	}
	page_count := count/limit + 1
	nav, _ := paging.P(page, page_count, 3, p)
	return nav
}
开发者ID:Laller,项目名称:nocrud,代码行数:19,代码来源:builtins.go

示例6: builtins

// We must recreate this map each time because map write is not threadsafe.
// Write will happen when a hook modifies the map (hook call is not implemented yet).
func builtins(ctx iface.Context) map[string]interface{} {
	viewCtx := ctx.ViewContext().Get()
	user := ctx.User()
	ret := map[string]interface{}{
		"get": func(s ...string) interface{} {
			return get(viewCtx, s...)
		},
		"date": date,
		"is_stranger": func() bool {
			return user.Level() == 0
		},
		"logged_in": func() bool {
			return user.Level() > 0
		},
		"is_moderator": func() bool {
			return user.Level() >= 200
		},
		"is_admin": func() bool {
			return user.Level() >= 300
		},
		"is_map":       isMap,
		"eq":           eq,
		"html":         html,
		"format_float": formatFloat,
		"fallback":     fallback,
		"type_of":      typeOf,
		"same_kind":    sameKind,
		"title":        strings.Title,
		"url": func(action_name string, i ...interface{}) string {
			return _url(ctx, action_name, i...)
		},
		"form": func(action_name string) *Form {
			return form(ctx, action_name)
		},
		"counter": newcounter,
		"get_sub": func(str string, params ...interface{}) []interface{} {
			return getSub(ctx, str, params...)
		},
		"get_list": func(str string, params ...interface{}) []interface{} {
			return getList(ctx, str, params...)
		},
		"elem": elem,
		"pager": func(pagesl []string, count, limited int) []paging.Pelem {
			var pagestr string
			if len(pagesl) == 0 {
				pagestr = "1"
			} else {
				pagestr = pagesl[0]
			}
			return pager(ctx, pagestr, count, limited)
		},
	}
	ctx.Conducting().Hooks().Select("AddTemplateBuiltin").Fire(ret)
	return ret
}
开发者ID:Laller,项目名称:nocrud,代码行数:57,代码来源:builtins.go

示例7: form

func form(ctx iface.Context, action_name string) *Form {
	nouns := scut.GetNouns(ctx.Options().Document())
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		panic(err)
	}
	f := hl.URLE().Form(action_name)
	return &Form{
		f,
	}
}
开发者ID:Laller,项目名称:nocrud,代码行数:12,代码来源:builtins.go

示例8: _url

func _url(ctx iface.Context, action_name string, i ...interface{}) string {
	if len(i)%2 == 1 {
		panic("Must be even.")
	}
	nouns := scut.GetNouns(ctx.Options().Document())
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		panic(err)
	}
	f := hl.URLE()
	inp := convert.ListToMap(i...)
	return f.UrlString(action_name, inp)
}
开发者ID:Laller,项目名称:nocrud,代码行数:14,代码来源:builtins.go

示例9: Init

func (c *C) Init(ctx iface.Context) {
	c.Basics.Hooks = ctx.Conducting().Hooks()
	c.Basics.Db = ctx.Db()
	c.opt = ctx.Options().Document().All().(map[string]interface{})
}
开发者ID:crufter,项目名称:nocrud,代码行数:5,代码来源:skeleton.go

示例10: Init

func (c *C) Init(ctx iface.Context) {
	c.client = ctx.Client()
	c.db = ctx.Db()
}
开发者ID:crufter,项目名称:nocrud,代码行数:4,代码来源:users.go

示例11: Init

func (c *C) Init(ctx iface.Context) {
	c.Basics.Hooks = ctx.Conducting().Hooks()
	c.Basics.Db = ctx.Db()
}
开发者ID:crufter,项目名称:nocrud,代码行数:4,代码来源:jsonedit.go

示例12: builtins

// We must recreate this map each time because map write is not threadsafe.
// Write will happen when a hook modifies the map (hook call is not implemented yet).
func builtins(ctx iface.Context) map[string]interface{} {
	viewCtx := ctx.ViewContext().Get()
	user := ctx.User()
	ret := map[string]interface{}{
		"get": func(s ...string) interface{} {
			return getMap(viewCtx, s...)
		},
		"getMap": getMap,
		"date":   date,
		"isStranger": func() bool {
			return user.Level() == 0
		},
		"loggedIn": func() bool {
			return user.Level() > 0
		},
		"isModerator": func() bool {
			return user.Level() >= 200
		},
		"isAdmin": func() bool {
			return user.Level() >= 300
		},
		"isMap":       isMap,
		"eq":          eq,
		"html":        html,
		"formatFloat": formatFloat,
		"newMap":      newMap,
		"newSlice":    newSlice,
		"fallback":    fallback,
		"typeOf":      typeOf,
		"sameKind":    sameKind,
		"title":       strings.Title,
		"url": func(action_name string, i ...interface{}) string {
			return _url(ctx, action_name, i...)
		},
		"form": func(action_name string) *Form {
			return form(ctx, action_name)
		},
		"counter": newcounter,
		"getSub": func(str string, params ...interface{}) []interface{} {
			return getSub(ctx, str, params...)
		},
		"getList": func(str string, params ...interface{}) []interface{} {
			return getList(ctx, str, params...)
		},
		"concat": concat,
		"index":  index,
		"pager": func(page interface{}, count, limited int) []paging.Pelem {
			var pagestr string
			if page == nil {
				pagestr = "1"
			} else {
				pagestr = page.(string)
			}
			return pager(ctx, pagestr, count, limited)
		},
		"len":     _len,
		"setMap":  setMap,
		"inSlice": inSlice,
		"hook": func(hookName string) *hook {
			return selectHook(ctx, hookName)
		},
		"indentedJSON": indentedJSON,
	}
	ctx.Conducting().Hooks().Select("AddTemplateBuiltin").Fire(ret)
	return ret
}
开发者ID:crufter,项目名称:nocrud,代码行数:68,代码来源:builtins.go

示例13: getSub

// Works from Get or GetSingle only.
func getSub(ctx iface.Context, noun string, params ...interface{}) []interface{} {
	nouns, ok := ctx.Options().Document().GetM("nouns")
	if !ok {
		panic("Can't find nouns.")
	}
	np := ctx.NonPortable()
	hl, err := highlev.New(ctx.Conducting().Hooks(), np.Resource(), nouns, np.Params())
	if err != nil {
		panic(err)
	}
	inp := convert.ListToMap(params...)
	subhl, err := hl.Sub(noun, inp)
	if err != nil {
		panic(err)
	}
	deflev_i, _ := ctx.Options().Document().Get("defaultLevel")
	deflev, _ := numcon.Int(deflev_i)
	ret, err := subhl.Run(ctx.Db(), ctx.User(), deflev)
	if err != nil {
		panic(err)
	}
	return ret
}
开发者ID:crufter,项目名称:nocrud,代码行数:24,代码来源:builtins.go

示例14: Init

func (c *C) Init(ctx iface.Context) {
	c.ctx = ctx
	c.nouns = scut.GetNouns(ctx.Options().Document())
}
开发者ID:crufter,项目名称:nocrud,代码行数:4,代码来源:terminal.go


注:本文中的github.com/opesun/nocrud/frame/interfaces.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。