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


Golang martini.Context类代码示例

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


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

示例1: LogOne

func LogOne(res http.ResponseWriter, req *http.Request, c martini.Context, logger *log.Logger) {
	start := time.Now()
	c.Next()

	rw := res.(martini.ResponseWriter)
	status := rw.Status()
	if status != 200 && status != 304 && req.URL.Path != "/ws" {
		logThis(start, res, req, logger)
		return
	}

	host, _, err := net.SplitHostPort(req.RemoteAddr)
	if err != nil {
		host = req.RemoteAddr
	}
	logOneLock.Lock()
	if _, ok := logged[host]; ok {
		logOneLock.Unlock()
		return
	}
	logged[host] = true
	logOneLock.Unlock()

	logger.Printf("%s\tRequested from %s; subsequent successful requests will not be logged\n", time.Now().Format("15:04:05"), host)
}
开发者ID:johntdyer,项目名称:golang-devops-stuff,代码行数:25,代码来源:server.go

示例2: withApp

func withApp(context martini.Context, params martini.Params, res http.ResponseWriter) {
	app := appreg.Get(params["name"])
	if app == nil {
		http.Error(res, "No such application.", 404)
	}
	context.Map(app)
}
开发者ID:jondot,项目名称:castbox,代码行数:7,代码来源:castbox.go

示例3: GET_home

func GET_home(c martini.Context, identity *data.Identity, render render.Render) {
	if identity == nil {
		c.Invoke(redirect_to("/login"))
	} else {
		c.Invoke(GET_profile)
	}
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:7,代码来源:get_home.go

示例4: inner_GET_authorize

func inner_GET_authorize(c martini.Context, sess sessions.Session, r *http.Request, ar *osin.AuthorizeRequest) bool {
	var (
		identity = ActiveIdentity(c)
		source   = current_url(r)
		handler  martini.Handler
	)

	if identity != nil {
		ar.UserData = identity
		sess.Delete("flow")
		return true
	} else {
		sess.Set("flow", FlowState{
			Type:    AuthorizeFlow,
			Source:  source,
			StartAt: time.Now(),
		})

		if provider := r.URL.Query().Get("p"); provider == "" {
			handler = show_provider_chooser()
		} else {
			handler = redirect_to_provider(provider)
		}
	}

	c.Invoke(handler)
	return false
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:28,代码来源:flow.go

示例5: create_identity

func create_identity(c martini.Context, tx *sqlx.Tx) {
	identity := &data.Identity{}
	err := data.CreateIdentity(tx, identity)
	if err != nil {
		panic(err)
	}

	c.Map(identity)
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:9,代码来源:flow.go

示例6: Middleware

func Middleware(ctx martini.Context, r *http.Request, w http.ResponseWriter) {
	sessionId := ensureCookie(r, w)
	session := sessionStore.Get(sessionId)

	ctx.Map(session)

	ctx.Next()

	sessionStore.Set(session)
}
开发者ID:evgeniy-maksimenko,项目名称:go-blog,代码行数:10,代码来源:session.go

示例7: SearcherMiddle

func SearcherMiddle(c martini.Context, w http.ResponseWriter, r *http.Request) {
	switch r.URL.Query().Get("type") {
	case "bing":
		c.MapTo(BingSearcher{}, (*Searcher)(nil))
		w.Header().Set("Content-Type", "application/json")
	default:
		c.MapTo(BingSearcher{}, (*Searcher)(nil))
		w.Header().Set("Content-Type", "application/json")
	}
}
开发者ID:huzorro,项目名称:gosearch,代码行数:10,代码来源:middle.go

示例8: ActiveIdentity

func ActiveIdentity(c martini.Context) *data.Identity {
	var (
		identity *data.Identity
	)

	c.Invoke(MayAuthenticate())

	c.Invoke(func(i *data.Identity) { identity = i })

	return identity
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:11,代码来源:do_authenticate.go

示例9: RequireLogin

func RequireLogin(rw http.ResponseWriter, req *http.Request,
	s sessions.Session, db *sql.DB, c martini.Context) {
	user := &User{}
	err := db.QueryRow("select name, email from users where id=$1", s.Get("userId")).Scan(&user.Name, &user.Email)

	if err != nil {
		http.Redirect(rw, req, "/login", http.StatusFound)
		return
	}

	c.Map(user)
}
开发者ID:jacnux,项目名称:Lessons,代码行数:12,代码来源:main.go

示例10: ConnectDB

func ConnectDB(r *http.Request, c martini.Context) string {

	host := r.FormValue("host")
	port := r.FormValue("port")
	client := riakpbc.NewClient([]string{
		host + ":" + port,
	})

	c.Map(client)
	return "connected"

}
开发者ID:raulmartinezm,项目名称:riak-inspector,代码行数:12,代码来源:main.go

示例11: must_authenticate

func must_authenticate(c martini.Context, sess sessions.Session, db *sqlx.DB, r *http.Request) {
	identity := ActiveIdentity(c)

	if identity != nil {
		return
	}

	if r.Header.Get("x-interactive") == "true" {
		sess.Delete("identity_id")
		c.Invoke(redirect_to("/login"))
	} else {
		c.Invoke(forbidden())
	}
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:14,代码来源:do_authenticate.go

示例12: GET_continue

func GET_continue(c martini.Context, params martini.Params) {
	var (
		provider = params["provider"]
		handler  martini.Handler
	)

	if provider == "" {
		handler = show_provider_chooser()
	} else {
		handler = redirect_to_provider(provider)
	}

	c.Invoke(handler)
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:14,代码来源:flow.go

示例13: may_authenticate

func may_authenticate(c martini.Context, sess sessions.Session, db *sqlx.DB, r *http.Request) {
	var (
		interactive = true
		token       string
		identity_id int64
		identity    *data.Identity
		err         error
	)

	// Attempt with Authorization header
	if v := r.Header.Get("Authorization"); v != "" {
		parts := strings.SplitN(v, " ", 2)
		if len(parts) == 2 && strings.ToLower(parts[0]) == "bearer" {
			interactive = false
			token = parts[1]
		}

		// Attempt with access_token parameter
	} else if v := r.URL.Query().Get("access_token"); v != "" {
		interactive = false
		token = v

		// Attempt with session.identity_id
	} else if id, ok := sess.Get("identity_id").(int64); ok {
		interactive = true
		identity_id = id
	}

	if token != "" {
		at, err := data.GetAccessTokenWithAccessToken(db, token)
		if err != nil {
			panic(err)
		}
		identity_id = at.IdentityId
	}

	if identity_id > 0 {
		identity, err = data.GetIdentity(db, identity_id)
		if err != nil {
			panic(err)
		}
	}

	if interactive {
		r.Header.Set("x-interactive", "true")
	}

	c.Map(identity)
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:49,代码来源:do_authenticate.go

示例14: GET_callback_AB

func GET_callback_AB(c martini.Context, sess sessions.Session) {
	flow := sess.Get("flow").(FlowState)

	c.Invoke(match_session_identity_with_account)
	c.Invoke(match_session_identity_with_flow)
	c.Invoke(update_account)
	c.Invoke(redirect_to(flow.Source))
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:8,代码来源:flow.go

示例15: GET_callback_BC

func GET_callback_BC(c martini.Context, sess sessions.Session) {
	flow := sess.Get("flow").(FlowState)

	c.Invoke(create_identity)
	c.Invoke(create_account)
	c.Invoke(activate_session)
	c.Invoke(redirect_to(flow.Source))
}
开发者ID:rogeriomarques,项目名称:oapx,代码行数:8,代码来源:flow.go


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