• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang objx.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestPublicData_WithArray

func TestPublicData_WithArray(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o1 := new(test.TestObjectWithFacade)
	o2 := new(test.TestObjectWithFacade)

	arr := []interface{}{o, o1, o2}

	o.Mock.On("PublicData", map[string]interface{}{}).Return(objx.New(map[string]interface{}{"theName": "1"}), nil)
	o1.Mock.On("PublicData", map[string]interface{}{}).Return(objx.New(map[string]interface{}{"theName": "2"}), nil)
	o2.Mock.On("PublicData", map[string]interface{}{}).Return(objx.New(map[string]interface{}{"theName": "3"}), nil)

	public, err := PublicData(arr, map[string]interface{}{})

	if assert.Nil(t, err) {
		assert.Equal(t, reflect.Slice, reflect.TypeOf(public).Kind(), "Result should be array not %v", reflect.TypeOf(public))
	}

	mock.AssertExpectationsForObjects(t, o.Mock, o1.Mock, o2.Mock)

	publicArray := public.([]interface{})
	if assert.Equal(t, 3, len(publicArray)) {
		assert.Equal(t, publicArray[0].(objx.Map).Get("theName").Str(), "1", "o")
		assert.Equal(t, publicArray[1].(objx.Map).Get("theName").Str(), "2", "o1")
		assert.Equal(t, publicArray[2].(objx.Map).Get("theName").Str(), "3", "o2")
	}

}
开发者ID:syohex,项目名称:codecs,代码行数:28,代码来源:facade_test.go


示例2: Check

func (rule *Rule) Check(cell *Cell) {
	if cell != nil && !rule.shouldCheck {
		// Don't invoke js if no cells mentioned in the
		// condition callback changed. If rules are run
		// not due to a cell being changed, still need
		// to call JS though.
		return
	}
	rule.tracker.StartTrackingDeps()
	shouldFire, newValue := rule.cond.Check(cell)
	var args objx.Map
	rule.tracker.StoreRuleDeps(rule)
	rule.shouldCheck = false

	switch {
	case !shouldFire:
		return
	case newValue != nil:
		args = objx.New(map[string]interface{}{
			"newValue": newValue,
		})
	case cell != nil:
		args = objx.New(map[string]interface{}{
			"device":   cell.DevName(),
			"cell":     cell.Name(),
			"newValue": cell.Value(),
		})
	}
	rule.then(args)
}
开发者ID:v12aml,项目名称:wb-rules,代码行数:30,代码来源:rule.go


示例3: loginHandler

func loginHandler(w http.ResponseWriter, r *http.Request) {
	segs := strings.Split(r.URL.Path, "/")
	action := segs[2]
	provider := segs[3]

	switch action {

	case "login":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("Error while getting provider:", provider, " : ", err)
		}
		loginUrl, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("Error while getting GetBeginAuthURL for", provider, " : ", err)
		}
		w.Header().Set("Location", loginUrl)
		w.WriteHeader(http.StatusTemporaryRedirect)

	case "callback":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("Error while getting provider:", provider, " : ", err)
		}
		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("Error while completing auth for", provider, " : ", err)
		}

		user, err := provider.GetUser(creds)
		if err != nil {
			log.Fatalln("Error while getting user for", provider)
		}

		// User Id is a md5 of the name
		m := md5.New()
		io.WriteString(m, strings.ToLower(user.Email()))
		userId := fmt.Sprintf("%x", m.Sum(nil))

		// save some data
		authCookieValue := objx.New(map[string]interface{}{
			"userid":     userId,
			"name":       user.Name(),
			"avatar_url": user.AvatarURL(),
			"email":      user.Email(),
		}).MustBase64()
		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/",
		})

		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)

	default:
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "Auth action %s not supported", action)
	}
}
开发者ID:oyvindsk,项目名称:go-blueprints-chat,代码行数:60,代码来源:auth.go


示例4: PublicDataMap

// PublicDataMap calls PublicData and returns the result after type asserting to objx.Map
func PublicDataMap(object interface{}, options map[string]interface{}) (objx.Map, error) {

	data, err := publicData(object, 0, options)

	if err != nil {
		return nil, err
	}

	if data == nil {
		return nil, nil
	}

	switch data.(type) {
	case map[string]interface{}:
		return objx.New(data.(map[string]interface{})), nil
	case objx.Map:
		return data.(objx.Map), nil
	default:
		if dataMap, ok := data.(objx.Map); ok {
			return dataMap, nil
		} else {
			panic(fmt.Sprintf("codecs: PublicDataMap must refer to a map[string]interface{} or objx.Map, not %s.  Did you mean to implement the Facade interface?", reflect.TypeOf(data)))
		}
	}
}
开发者ID:syohex,项目名称:codecs,代码行数:26,代码来源:facade.go


示例5: callbackHandler

func callbackHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	providerName := kami.Param(ctx, "provider")

	provider, err := gomniauth.Provider(providerName)
	if err != nil {
		log.Fatalln("認証プロバイダーの取得に失敗しました", provider, "-", err)
	}
	creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
	if err != nil {
		log.Fatalln("認証を完了できませんでした", provider, "-", err)
	}
	user, err := provider.GetUser(creds)
	if err != nil {
		log.Fatalln("ユーザーの取得に失敗しました", provider, "- ", err)
	}

	authCookieValue := objx.New(map[string]interface{}{
		"name": user.Name(),
	}).MustBase64()

	http.SetCookie(w, &http.Cookie{
		Name:  "auth",
		Value: authCookieValue,
		Path:  "/"})
	log.Println("######### ", authCookieValue)

	w.Header()["Location"] = []string{"/"}
	w.WriteHeader(http.StatusTemporaryRedirect)
}
开发者ID:kyokomi-sandbox,项目名称:sandbox,代码行数:29,代码来源:gomniauth.go


示例6: getJSObject

func (ctx *ESContext) getJSObject(objIndex int, top bool) interface{} {
	t := duktape.Type(ctx.GetType(-1))
	switch {
	case t.IsNone() || t.IsUndefined() || t.IsNull(): // FIXME
		return nil // FIXME
	case t.IsBool():
		return ctx.GetBoolean(objIndex)
	case t.IsNumber():
		return ctx.GetNumber(objIndex)
	case t.IsString():
		return ctx.GetString(objIndex)
	case t.IsObject():
		if ctx.IsArray(objIndex) {
			return ctx.getArray(objIndex)
		}
		m := ctx.getObject(objIndex)
		if top {
			return objx.New(m)
		} else {
			return m
		}
	case t.IsBuffer():
		wbgo.Error.Println("buffers aren't supported yet")
		return nil
	case t.IsPointer():
		return ctx.GetPointer(objIndex)
	default:
		wbgo.Error.Panicf("bad object type %d", t)
		return nil // avoid compiler warning
	}
}
开发者ID:v12aml,项目名称:wb-rules,代码行数:31,代码来源:escontext.go


示例7: loginHandler

// loginHandlerはサードパーティーへのログインの処理を受け持ちます
// パスの形式: /auth/{action}/{provider}
func loginHandler(w http.ResponseWriter, r *http.Request) {
	segs := strings.Split(r.URL.Path, "/")
	action := segs[2]
	provider := segs[3]
	switch action {
	case "login":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("認証プロバイダーの取得に失敗しました:", provider, "-", err)
		}
		loginUrl, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("GetBeginAuthURL の呼び出し中にエラーが発生しました:", provider, "-", err)
		}
		w.Header().Set("Location", loginUrl)
		w.WriteHeader(http.StatusTemporaryRedirect)
	case "callback":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("認証プロバイダーの取得に失敗しました", provider, "-", err)
		}

		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("認証を完了できませんでした", provider, "-", err)
		}

		user, err := provider.GetUser(creds)
		if err != nil {
			log.Fatalln("ユーザーの取得に失敗しました", provider, "-", err)
		}

		chatUser := &chatUser{User: user}
		m := md5.New()
		io.WriteString(m, strings.ToLower(user.Name()))
		chatUser.uniqueID = fmt.Sprintf("%x", m.Sum(nil))
		avatarURL, err := avatars.GetAvatarURL(chatUser)
		if err != nil {
			log.Fatalln("GetAvatarURLに失敗しました", "-", err)
		}

		// データを保存します
		authCookieValue := objx.New(map[string]interface{}{
			"userid":     chatUser.uniqueID,
			"name":       user.Name(),
			"avatar_url": avatarURL,
		}).MustBase64()
		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/"})

		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	default:
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "アクション%sには非対応です", action)
	}
}
开发者ID:masutaka,项目名称:goblueprints,代码行数:61,代码来源:auth.go


示例8: loginHandler

//loginHandler handle the third party login process
//format: /auth/{action}/{provider}
func loginHandler(w http.ResponseWriter, r *http.Request) {
	segs := strings.Split(r.URL.Path, "/")
	if len(segs) != 4 {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprintf(w, "Invalid URL path %s", r.URL.Path)
		return
	}
	action := segs[2]
	provider := segs[3]
	switch action {
	case "login":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("Error when trying to get provider", provider, "-", err)
		}
		loginURL, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("Error when trying to GetBeginAuthURL for", provider, "-", err)
		}
		w.Header().Set("Location", loginURL)
		w.WriteHeader(http.StatusTemporaryRedirect)
	case "callback":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("Error when trying to get provider", provider, "-", err)
		}
		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("Error when trying to complete auth for", provider, "-", err)
		}
		user, err := provider.GetUser(creds)
		if err != nil {
			log.Fatalln("Error when trying to get user creds for", provider, "-", err)
		}
		chatUser := &chatUser{User: user}
		m := md5.New()
		io.WriteString(m, strings.ToLower(user.Email()))
		userid := fmt.Sprintf("%x", m.Sum(nil))
		chatUser.uniqueID = userid
		avatarURL, err := avatars.GetAvatarURL(chatUser)
		if err != nil {
			log.Fatalln("Error when trying to getAvatarURL", "-", err)
		}
		authCookieValue := objx.New(map[string]interface{}{
			"userID":     userid,
			"name":       user.Name(),
			"avatar_url": avatarURL,
		}).MustBase64()
		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/"})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	default:
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "Auth action %s not supported", action)
	}
}
开发者ID:onufert,项目名称:chat,代码行数:61,代码来源:auth.go


示例9: loginHandler

// loginHandler handles the third-party login process.
func loginHandler(w http.ResponseWriter, r *http.Request) {
	segs := strings.Split(r.URL.Path, "/")
	action := segs[2]
	provider := segs[3]
	switch action {
	case "login":

		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("Error when trying to get provider", provider, "-", err)
		}

		loginUrl, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("Error when trying to GetBeginAuthURL for", provider, "-", err)
		}

		w.Header()["Location"] = []string{loginUrl}
		w.WriteHeader(http.StatusTemporaryRedirect)

	case "callback":

		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("Error when trying to get provider", provider, "-", err)
		}

		// get the credentials
		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("Error when trying to complete auth for", provider, "-", err)
		}

		// get the user
		user, err := provider.GetUser(creds)
		if err != nil {
			log.Fatalln("Error when trying to get user from", provider, "-", err)
		}

		// save some data
		authCookieValue := objx.New(map[string]interface{}{
			"name": user.Name(),
		}).MustBase64()
		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/"})

		w.Header().Set("Location", "/chat")
		w.WriteHeader(http.StatusTemporaryRedirect)

	default:
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "Auth action %s not supported", action)
	}
}
开发者ID:0-T-0,项目名称:goblueprints,代码行数:57,代码来源:auth.go


示例10: ProviderPublicData

// ProviderPublicData gets the public data for the specified provider.
//
// The options should contain the `loginpathFormat`, which will determine how the
// loginpath value is created.
func ProviderPublicData(provider common.Provider, options map[string]interface{}) (interface{}, error) {

	optionsx := objx.New(options)

	return map[string]interface{}{
		"name":      provider.Name(),
		"display":   provider.DisplayName(),
		"loginpath": fmt.Sprintf(optionsx.Get("loginpathFormat").Str("auth/%s/login"), provider.Name()),
	}, nil

}
开发者ID:amencarini,项目名称:gomniauth,代码行数:15,代码来源:facade.go


示例11: loginHandler

func loginHandler(w http.ResponseWriter, r *http.Request) {
	segs := strings.Split(r.URL.Path, "/")
	action := segs[2]
	provider := segs[3]
	switch action {

	case "login":

		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatal("Failed autorizatoin: ", provider, "-", err)
		}

		loginURL, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("Had error during calling GetBeginAuthURL:", provider, "-", err)
		}

		w.Header().Set("Location", loginURL)
		w.WriteHeader(http.StatusTemporaryRedirect)

	case "callback":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("failed to get authorization from auth provider", provider, "-", err)
		}

		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("Could not finish authorization", provider, "-", err)
		}

		user, err := provider.GetUser(creds)
		if err != nil {
			log.Fatalln("failed get user", provider, "-", err)
		}

		authCookieValue := objx.New(map[string]interface{}{
			"name":       user.Name(),
			"avatar_url": user.AvatarURL(),
		}).MustBase64()

		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/"})
		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)

	default:
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "can't handle action: %s", action)
	}
}
开发者ID:TakaakiFuruse,项目名称:go_practice,代码行数:54,代码来源:auth.go


示例12: esWbSpawn

func (engine *ESEngine) esWbSpawn() int {
	if engine.ctx.GetTop() != 5 || !engine.ctx.IsArray(0) || !engine.ctx.IsBoolean(2) ||
		!engine.ctx.IsBoolean(3) {
		return duktape.DUK_RET_ERROR
	}

	args := engine.ctx.StringArrayToGo(0)
	if len(args) == 0 {
		return duktape.DUK_RET_ERROR
	}

	callbackFn := ESCallbackFunc(nil)

	if engine.ctx.IsFunction(1) {
		callbackFn = engine.ctx.WrapCallback(1)
	} else if !engine.ctx.IsNullOrUndefined(1) {
		return duktape.DUK_RET_ERROR
	}

	var input *string
	if engine.ctx.IsString(4) {
		instr := engine.ctx.GetString(4)
		input = &instr
	} else if !engine.ctx.IsNullOrUndefined(4) {
		return duktape.DUK_RET_ERROR
	}

	captureOutput := engine.ctx.GetBoolean(2)
	captureErrorOutput := engine.ctx.GetBoolean(3)
	go func() {
		r, err := Spawn(args[0], args[1:], captureOutput, captureErrorOutput, input)
		if err != nil {
			wbgo.Error.Printf("external command failed: %s", err)
			return
		}
		if callbackFn != nil {
			engine.model.CallSync(func() {
				args := objx.New(map[string]interface{}{
					"exitStatus": r.ExitStatus,
				})
				if captureOutput {
					args["capturedOutput"] = r.CapturedOutput
				}
				args["capturedErrorOutput"] = r.CapturedErrorOutput
				callbackFn(args)
			})
		} else if r.ExitStatus != 0 {
			wbgo.Error.Printf("command '%s' failed with exit status %d",
				strings.Join(args, " "), r.ExitStatus)
		}
	}()
	return 0
}
开发者ID:v12aml,项目名称:wb-rules,代码行数:53,代码来源:esengine.go


示例13: loginHandler

func loginHandler(w http.ResponseWriter, r *http.Request) {
	segs := strings.Split(r.URL.Path, "/")
	action := segs[2]
	provider := segs[3]

	switch action {
	case "login":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("Failed to get authentication provider from ", provider, " - ", err)
		}
		loginURL, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("Failed in GetBeginAuthURL for ", provider, " - ", err)
		}
		w.Header().Set("Location", loginURL)
		w.WriteHeader(http.StatusTemporaryRedirect)
	case "callback":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("Failed to get authentication provider from ", provider, " - ", err)
		}

		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("Failed in authentication for ", provider, " - ", err)
		}

		user, err := provider.GetUser(creds)
		if err != nil {
			log.Fatalln("Failed to get user from ", provider, " - ", err)
		}

		authCookieValue := objx.New(map[string]interface{}{
			"name":  user.Name(),
			"email": user.Email(),
		}).MustBase64()

		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/",
		})

		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	default:
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "action %s is not supported", action)
	}
}
开发者ID:feeblefakie,项目名称:misc,代码行数:51,代码来源:auth.go


示例14: loginHandler

func loginHandler(w http.ResponseWriter, r *http.Request) {
	segs := strings.Split(r.URL.Path, "/")
	action := segs[2]
	provider := segs[3]
	switch action {
	case "login":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("認証プロバイダーの取得に失敗しました:", provider, "-", err)
		}
		loginUrl, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("GetBeginAuthURLの呼び出し中にエラーが発生しました", provider, "-", err)
		}
		w.Header().Set("Location", loginUrl)
		w.WriteHeader(http.StatusTemporaryRedirect)
	case "callback":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("認証プロバイダーの取得に失敗しました。", provider, "-", err)
		}

		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("認証を完了できませんでした", provider, "-", err)
		}

		user, err := provider.GetUser(creds)

		if err != nil {
			log.Fatalln("ユーザーの取得に失敗しました", provider, "-", err)
		}

		authCookieValue := objx.New(map[string]interface{}{
			"name": user.Name(),
		}).MustBase64()

		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/",
		})

		w.Header().Set("Location", "/chat")
		w.WriteHeader(http.StatusTemporaryRedirect)

	default:
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "アクション%sには非対応です", action)
	}
}
开发者ID:mosson,项目名称:chat-sample,代码行数:51,代码来源:auth.go


示例15: TestPublicDataMap

func TestPublicDataMap(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o.Mock.On("PublicData", map[string]interface{}{}).Return(objx.New(map[string]interface{}{"theName": "Mat"}), nil)

	public, err := PublicDataMap(o, map[string]interface{}{})

	if assert.Nil(t, err) {
		assert.Equal(t, public.Get("theName").Str(), "Mat")
	}

	mock.AssertExpectationsForObjects(t, o.Mock)

}
开发者ID:syohex,项目名称:codecs,代码行数:14,代码来源:facade_test.go


示例16: loginHandler

func loginHandler(w http.ReponseWriter, r *http.Request) {
	segs := strings.Split(r.URL.Path, "/")
	action := segs[2]
	provider := segs[3]
	switch action {
	case "login":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("fail to get provider", provider, "-", err)
		}
		loginUrl, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("error GetBeginAuthURL", provider, "-", err)
		}
		w.Header().Set("Location", loginUrl)
		w.WriteHeader(http.StatusTemporaryRedirect)
	case "callback":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("fail to get provider", provider, "-", err)
		}
		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("error CompleteAuth", provider, "-", err)
		}
		user, err := provider.GetUser(creds)
		if err != nil {
			log.Fatalln("error GetUser", provider, "-", err)
		}
		authCookieValue := objx.New(map[string]interface{}{
			"name": user.Name(),
		}).MustBase64()
		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/",
		})
		w.Header()["Location"] = []string("/2/1")
		w.WriteHeader(http.StatusTemporaryRedirect)

	default:
		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "not accept %s", action)
	}
}
开发者ID:ntk1000,项目名称:go-web-book-playground,代码行数:45,代码来源:auth.go


示例17: Marshal

// Marshal converts an object to a []byte representation.
// You can optionally pass additional arguments to further customize this call.
func (c *SimpleXmlCodec) Marshal(object interface{}, options map[string]interface{}) ([]byte, error) {

	var output []string

	// add the declaration
	output = append(output, XMLDeclaration)

	// add the rest of the XML
	bytes, err := marshal(object, true, 0, objx.New(options))

	if err != nil {
		return nil, err
	}

	output = append(output, string(bytes))

	// return the output
	return []byte(strings.Join(output, "")), nil
}
开发者ID:syohex,项目名称:codecs,代码行数:21,代码来源:simple_xml_codec.go


示例18: esWbCellObject

func (engine *ESEngine) esWbCellObject() int {
	if engine.ctx.GetTop() != 2 || !engine.ctx.IsString(-1) || !engine.ctx.IsObject(-2) {
		return duktape.DUK_RET_ERROR
	}
	devProxy, ok := engine.ctx.GetGoObject(-2).(*DeviceProxy)
	if !ok {
		wbgo.Error.Printf("invalid _wbCellObject call")
		return duktape.DUK_RET_TYPE_ERROR
	}
	cellProxy := devProxy.EnsureCell(engine.ctx.GetString(-1))
	engine.ctx.PushGoObject(cellProxy)
	engine.ctx.DefineFunctions(map[string]func() int{
		"rawValue": func() int {
			engine.ctx.PushString(cellProxy.RawValue())
			return 1
		},
		"value": func() int {
			m := objx.New(map[string]interface{}{
				"v": cellProxy.Value(),
			})
			engine.ctx.PushJSObject(m)
			return 1
		},
		"setValue": func() int {
			if engine.ctx.GetTop() != 1 || !engine.ctx.IsObject(-1) {
				return duktape.DUK_RET_ERROR
			}
			m, ok := engine.ctx.GetJSObject(-1).(objx.Map)
			if !ok || !m.Has("v") {
				wbgo.Error.Printf("invalid cell definition")
				return duktape.DUK_RET_TYPE_ERROR
			}
			cellProxy.SetValue(m["v"])
			return 1
		},
		"isComplete": func() int {
			engine.ctx.PushBoolean(cellProxy.IsComplete())
			return 1
		},
	})
	return 1
}
开发者ID:v12aml,项目名称:wb-rules,代码行数:42,代码来源:esengine.go


示例19: TestPublicData_WithRecursion_WithObjects

func TestPublicData_WithRecursion_WithObjects(t *testing.T) {

	o := new(test.TestObjectWithFacade)
	o1 := new(test.TestObjectWithFacade)
	o2 := new(test.TestObjectWithFacade)

	args := map[string]interface{}{constants.OptionKeyClientCallback: "~d"}

	o.Mock.On("PublicData", args).Return(o1, nil)
	o1.Mock.On("PublicData", args).Return(o2, nil)
	o2.Mock.On("PublicData", args).Return(objx.New(map[string]interface{}{"theName": "Mat"}), nil)

	public, err := PublicData(o, args)

	if assert.Nil(t, err) {
		assert.Equal(t, public.(objx.Map).Get("theName").Str(), "Mat")
	}

	mock.AssertExpectationsForObjects(t, o.Mock, o1.Mock, o2.Mock)

}
开发者ID:syohex,项目名称:codecs,代码行数:21,代码来源:facade_test.go


示例20: loginHandler

// loginHandler handles the third-party login process
// format: /auth/{action}/{provider}
// callback: /auth/callback/{provider}
func loginHandler(w http.ResponseWriter, r *http.Request) {
	log.Println("req url path:", r.URL.Path)

	segs := strings.Split(r.URL.Path, "/")
	action := segs[2]
	provider := segs[3]

	switch action {
	case "login":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("error when trying to get provider", provider, "-", err)
		}
		loginUrl, err := provider.GetBeginAuthURL(nil, nil)
		if err != nil {
			log.Fatalln("error when trying to get GetBeginAuthURL for", provider, "-", err)
		}
		w.Header().Set("Location", loginUrl)
		w.WriteHeader(http.StatusTemporaryRedirect)
	case "callback":
		provider, err := gomniauth.Provider(provider)
		if err != nil {
			log.Fatalln("error when trying to get provider", provider, "-", err)
		}

		creds, err := provider.CompleteAuth(objx.MustFromURLQuery(r.URL.RawQuery))
		if err != nil {
			log.Fatalln("error when trying to complete auth for", provider, "-", err)
		}

		user, err := provider.GetUser(creds)
		if err != nil {
			log.Fatalln("error when trying to get user from", provider, "-", err)
		}

		// log.Println("user name:", user.Name())
		// log.Println("user avatar url:", user.AvatarURL())

		m := md5.New()
		io.WriteString(m, strings.ToLower(user.Name()))

		chatUser := &chatUser{User: user}
		chatUser.uniqueId = fmt.Sprintf("%x", m.Sum(nil))

		avatarUrl, err := avatars.GetAvatarURL(chatUser)
		if err != nil {
			log.Fatalln("error when trying to GetAvatarURL", "-", err)
		}

		// save some data
		authCookieValue := objx.New(map[string]interface{}{
			"userid":     chatUser.UniqueId(),
			"name":       user.Name(),
			"avatar_url": avatarUrl,
		}).MustBase64()

		http.SetCookie(w, &http.Cookie{
			Name:  "auth",
			Value: authCookieValue,
			Path:  "/",
		})

		w.Header()["Location"] = []string{"/chat"}
		w.WriteHeader(http.StatusTemporaryRedirect)
	default:
		// todo: use /auth/nonsense ?

		w.WriteHeader(http.StatusNotFound)
		fmt.Fprintf(w, "Auth action %s not supported", action)
	}
}
开发者ID:hongjianzhu,项目名称:go-chat,代码行数:74,代码来源:auth.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang objx.Map类代码示例发布时间:2022-05-28
下一篇:
Golang objx.MustFromURLQuery函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap