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


Golang jsonhelper.NewJSONObject函数代码示例

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


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

示例1: OutputTo

func (p *JSONMediaTypeInputHandler) OutputTo(req wm.Request, cxt wm.Context, writer io.Writer) (int, http.Header, os.Error) {
	defer func() {
		if p.reader != nil {
			if closer, ok := p.reader.(io.Closer); ok {
				closer.Close()
			}
		}
	}()
	//log.Printf("[JSONMTIH]: Calling OutputTo with reader %v\n", p.reader)
	if p.reader == nil {
		return p.handler.HandleJSONObjectInputHandler(req, cxt, writer, nil)
	}
	obj := jsonhelper.NewJSONObject()
	dec := json.NewDecoder(p.reader)
	err := dec.Decode(&obj)
	if err != nil {
		headers := make(http.Header)
		//headers.Set("Content-Type", wm.MIME_TYPE_JSON)
		m := jsonhelper.NewJSONObject()
		w := json.NewEncoder(writer)
		m.Set("status", "error")
		m.Set("message", err.String())
		m.Set("result", nil)
		w.Encode(m)
		return 500, headers, err
	}
	return p.handler.HandleJSONObjectInputHandler(req, cxt, writer, obj)
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:28,代码来源:jsonmediatypeinputhandler.go

示例2: OutputTo

func (p *JSONMediaTypeHandler) OutputTo(req wm.Request, cxt wm.Context, writer io.Writer, resp wm.ResponseWriter) {
	buf := bytes.NewBufferString("")
	obj := jsonhelper.NewJSONObject()
	enc := json.NewEncoder(buf)
	obj.Set("status", "success")
	obj.Set("result", p.obj)
	err := enc.Encode(obj)
	if err != nil {
		//resp.Header().Set("Content-Type", wm.MIME_TYPE_JSON)
		if !p.writtenStatusHeader {
			resp.WriteHeader(500)
			p.writtenStatusHeader = true
		}
		m := jsonhelper.NewJSONObject()
		w := json.NewEncoder(writer)
		m.Set("status", "error")
		m.Set("message", err.String())
		m.Set("result", nil)
		w.Encode(m)
		return
	}
	//resp.Header().Set("Content-Type", wm.MIME_TYPE_JSON)
	resp.Header().Set("Content-Length", strconv.Itoa(buf.Len()))
	if p.lastModified != nil {
		resp.Header().Set("Last-Modified", p.lastModified.Format(http.TimeFormat))
	}
	if len(p.etag) > 0 {
		resp.Header().Set("ETag", strconv.Quote(p.etag))
	}
	handler := wm.NewPassThroughMediaTypeHandler(wm.MIME_TYPE_JSON, ioutil.NopCloser(bytes.NewBuffer(buf.Bytes())), int64(buf.Len()), p.lastModified)
	handler.OutputTo(req, cxt, writer, resp)
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:32,代码来源:jsonmediatypehandler.go

示例3: TestAuthSetPasswordAdmin

func TestAuthSetPasswordAdmin(t *testing.T) {
	ds, wm := initializeAuthUserAccountDS()
	user, _ := ds.FindUserAccountByUsername("firstpresident")
	accessKeys, _, _ := ds.RetrieveUserKeys(user.Id, nil, 1000)
	if len(accessKeys) != 1 {
		t.Error("Expected to find 1 access key stored, but found", len(accessKeys))
	}
	accessKey := accessKeys[0]
	jsonobj := jsonhelper.NewJSONObject()
	jsonobj.Set("password", "hi ho hi ho")
	jsonbuf, _ := json.Marshal(jsonobj)
	req, _ := http.NewRequest(webmachine.POST, "http://localhost/api/v1/json/auth/set_password/", bytes.NewBuffer(jsonbuf))
	req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
	req.Header.Set("Accept-Charset", "utf-8")
	req.Header.Set("Accept-Encoding", "identity")
	req.Header.Set("Accept-Language", "en-us")
	req.Header.Set("Connection", "close")
	apiutil.NewSigner(accessKey.Id, accessKey.PrivateKey).SignRequest(req, 0)
	reqbytes, _ := httputil.DumpRequest(req, true)
	t.Log("Request is:\n", string(reqbytes), "\n\n")
	resp := webmachine.NewMockResponseWriter(req)
	wm.ServeHTTP(resp, req)
	t.Log("Response is:\n", resp.String(), "\n\n")
	if resp.StatusCode != http.StatusOK {
		t.Error("Expected ", http.StatusOK, " status code but received ", resp.StatusCode)
	}
	if resp.Header().Get("Content-Type") != req.Header.Get("Accept") {
		t.Error("Expected Content-Type \"", req.Header.Get("Accept"), "\" but received ", resp.Header().Get("Content-Type"))
	}
	obj := jsonhelper.NewJSONObject()
	err := json.Unmarshal(resp.Buffer.Bytes(), &obj)
	if err != nil {
		t.Error("Unable to unmarshal setPassword response due to error:", err.Error())
	}
	if status := obj.GetAsString("status"); status != "success" {
		t.Error("Expected successful operation, but had status:", status)
	}
	result := obj.GetAsObject("result")
	if message := result.GetAsString("message"); message != "password changed" {
		t.Error("Expected message == \"password changed\", but was \"", message, "\"")
	}
	user2 := result.GetAsObject("user")
	uid := user2.GetAsString("id")
	if uid != user.Id {
		t.Error("Expected user id of", user.Id, ", but was", uid)
	}
	accessKeys2, _, _ := ds.RetrieveUserKeys(user.Id, nil, 1000)
	if len(accessKeys2) != 1 {
		t.Error("Expected to find one access key stored, but found", len(accessKeys))
	}
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:51,代码来源:set_password_test.go

示例4: MediaTypeHandleOutputTo

func (p *JSONMediaTypeHandler) MediaTypeHandleOutputTo(req wm.Request, cxt wm.Context, writer io.Writer, resp wm.ResponseWriter) {
	var responseHeaders http.Header
	var responseStatusCode int
	if p.obj == nil && p.responseGenerator != nil {
		p.obj, p.lastModified, p.etag, responseStatusCode, responseHeaders = p.responseGenerator()
	}
	buf := bytes.NewBufferString("")
	obj := jsonhelper.NewJSONObject()
	enc := json.NewEncoder(buf)
	obj.Set("status", "success")
	obj.Set("result", p.obj)
	err := enc.Encode(obj)
	if err != nil {
		//resp.Header().Set("Content-Type", wm.MIME_TYPE_JSON)
		if !p.writtenStatusHeader {
			resp.WriteHeader(500)
			p.writtenStatusHeader = true
		}
		m := jsonhelper.NewJSONObject()
		w := json.NewEncoder(writer)
		m.Set("status", "error")
		m.Set("message", err.Error())
		m.Set("result", nil)
		w.Encode(m)
		return
	}
	if responseHeaders != nil {
		for k, arr := range responseHeaders {
			if _, ok := resp.Header()[k]; ok {
				if len(arr) > 0 {
					resp.Header().Set(k, arr[len(arr)-1])
				}
			} else {
				for _, v := range arr {
					resp.Header().Add(k, v)
				}
			}
		}
	}
	//resp.Header().Set("Content-Type", wm.MIME_TYPE_JSON)
	resp.Header().Set("Content-Length", strconv.Itoa(buf.Len()))
	if !p.lastModified.IsZero() {
		resp.Header().Set("Last-Modified", p.lastModified.Format(http.TimeFormat))
	}
	if len(p.etag) > 0 {
		resp.Header().Set("ETag", strconv.Quote(p.etag))
	}
	handler := wm.NewPassThroughMediaTypeHandler(wm.MIME_TYPE_JSON, ioutil.NopCloser(bytes.NewBuffer(buf.Bytes())), int64(buf.Len()), p.lastModified)
	handler.SetStatusCode(responseStatusCode)
	handler.MediaTypeHandleOutputTo(req, cxt, writer, resp)
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:51,代码来源:jsonmediatypehandler.go

示例5: TestAuthLoginNoPassword

func TestAuthLoginNoPassword(t *testing.T) {
	ds, wm := initializeAuthUserAccountDS()
	user, _ := ds.FindUserAccountByUsername("firstpresident")
	accessKeys, _, _ := ds.RetrieveUserKeys(user.Id, nil, 1000)
	if len(accessKeys) == 0 {
		t.Error("Expected to find at least one access key stored.")
	}
	jsonobj := jsonhelper.NewJSONObject()
	jsonobj.Set("username", user.Username)
	jsonbuf, _ := json.Marshal(jsonobj)
	req, _ := http.NewRequest(webmachine.POST, "http://localhost/api/v1/json/auth/login/", bytes.NewBuffer(jsonbuf))
	req.Header.Set("Content-Type", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
	req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
	req.Header.Set("Accept-Charset", "utf-8")
	req.Header.Set("Accept-Encoding", "identity")
	req.Header.Set("Accept-Language", "en-us")
	req.Header.Set("Connection", "close")
	reqbytes, _ := httputil.DumpRequest(req, true)
	t.Log("Request is:\n", string(reqbytes), "\n\n")
	resp := webmachine.NewMockResponseWriter(req)
	wm.ServeHTTP(resp, req)
	t.Log("Response is:\n", resp.String(), "\n\n")
	if resp.StatusCode != http.StatusUnauthorized {
		t.Error("Expected ", http.StatusUnauthorized, " status code but received ", resp.StatusCode)
	}
	if resp.Header().Get("Content-Type") != req.Header.Get("Accept") {
		t.Error("Expected Content-Type \"", req.Header.Get("Accept"), "\" but received ", resp.Header().Get("Content-Type"))
	}
	obj := jsonhelper.NewJSONObject()
	err := json.Unmarshal(resp.Buffer.Bytes(), &obj)
	if err != nil {
		t.Error("Unable to unmarshal login response due to error:", err.Error())
	}
	if status := obj.GetAsString("status"); status != "error" {
		t.Error("Expected error operation, but had status:", status)
	}
	result := obj.GetAsObject("result")
	if result.Len() != 1 {
		t.Error("Expected a result object with 1 entry, but has", result.Len(), "entries as:", result)
	}
	if password := result.GetAsArray("password"); len(password) != 1 || password[0] != auth.ERR_MUST_SPECIFY_PASSWORD.Error() {
		t.Error("Expected one error for missing password, but was", result)
	}
	if message := obj.GetAsString("message"); message != auth.ERR_VALUE_ERRORS.Error() {
		t.Error("Expected ERR_VALUE_ERRORS for message, but was", message)
	}
	if accessKeys2, _, _ := ds.RetrieveUserKeys(user.Id, nil, 1000); len(accessKeys2) != 1 {
		t.Error("Expected 1 access key after logging in, but found", len(accessKeys2))
	}
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:50,代码来源:login_test.go

示例6: GenerateRequestTokenUrl

func (p *googleplusClient) GenerateRequestTokenUrl(properties jsonhelper.JSONObject) string {
	if properties == nil {
		properties = jsonhelper.NewJSONObject()
	}
	m := make(url.Values)
	m.Add("response_type", "code")
	if v, ok := properties["client_id"]; ok && len(v.(string)) > 0 {
		m.Add("client_id", v.(string))
	} else {
		m.Add("client_id", p.clientId)
	}
	if v, ok := properties["redirect_uri"]; ok {
		if len(v.(string)) > 0 {
			m.Add("redirect_uri", v.(string))
		}
	} else if len(p.redirectUri) > 0 {
		m.Add("redirect_uri", p.redirectUri)
	}
	if v, ok := properties["scope"]; ok {
		if len(v.(string)) > 0 {
			m.Add("scope", v.(string))
		}
	} else if len(p.scope) > 0 {
		m.Add("scope", p.scope)
	}
	if v, ok := properties["state"]; ok {
		if len(v.(string)) > 0 {
			m.Add("state", v.(string))
		}
	} else if len(p.state) > 0 {
		m.Add("state", p.state)
	}
	return MakeUrl(_GOOGLEPLUS_ACCESS_TOKEN_URL, m)
}
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:34,代码来源:googleplus.go

示例7: HandleInputHandlerAfterSetup

func (p *LoginAccountRequestHandler) HandleInputHandlerAfterSetup(lac LoginAccountContext) (int, http.Header, io.WriterTo) {
	errors := make(map[string][]error)
	user, err := lac.ValidateLogin(p.ds, p.authDS, errors)
	if len(errors) > 0 {
		if err != nil {
			return apiutil.OutputErrorMessage(err.Error(), errors, http.StatusBadRequest, nil)
		}
		return apiutil.OutputErrorMessage(ERR_VALUE_ERRORS.Error(), errors, http.StatusUnauthorized, nil)
	}
	if err == ERR_INVALID_USERNAME_PASSWORD_COMBO {
		return apiutil.OutputErrorMessage(err.Error(), nil, http.StatusUnauthorized, nil)
	}
	if err != nil {
		return apiutil.OutputErrorMessage("Unable to process login request: ", nil, http.StatusInternalServerError, nil)
	}
	if user == nil {
		return apiutil.OutputErrorMessage("Unable to process login request: no such username", nil, http.StatusUnauthorized, nil)
	}
	accessKey, err := p.authDS.StoreAccessKey(dm.NewAccessKey(user.Id, ""))
	if err != nil {
		return apiutil.OutputErrorMessage("Unable to process login request: "+err.Error(), nil, http.StatusInternalServerError, nil)
	}
	obj := jsonhelper.NewJSONObject()
	obj.Set("user_id", user.Id)
	obj.Set("username", user.Username)
	obj.Set("name", user.Name)
	obj.Set("access_key_id", accessKey.Id)
	obj.Set("private_key", accessKey.PrivateKey)
	lac.SetResult(obj)
	return 0, nil, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:31,代码来源:login.go

示例8: UnmarshalJSON

func (p *facebookLocation) UnmarshalJSON(data []byte) error {
	props := jsonhelper.NewJSONObject()
	err := json.Unmarshal(data, &props)
	p.id = props.GetAsString("id")
	p.name = props.GetAsString("name")
	return err
}
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:7,代码来源:facebook.go

示例9: HandleInputHandlerAfterSetup

func (p *SetPasswordRequestHandler) HandleInputHandlerAfterSetup(cxt SetPasswordContext) (int, http.Header, io.WriterTo) {
	errors := make(map[string][]error)
	var obj jsonhelper.JSONObject
	var err error
	authDS := p.authDS
	if user := cxt.User(); user != nil {
		var userPassword *dm.UserPassword
		if user != nil {
			userPassword = dm.NewUserPassword(user.Id, cxt.Password())
		} else {
			userPassword = dm.NewUserPassword("", cxt.Password())
		}
		userPassword.Validate(true, errors)
		if len(errors) == 0 {
			userPassword, err = authDS.StoreUserPassword(userPassword)
		}
		obj = jsonhelper.NewJSONObject()
		userObj, _ := jsonhelper.Marshal(user)
		obj.Set("user", userObj)
		obj.Set("type", "user")
		obj.Set("message", "password changed")
	} else {
		return apiutil.OutputErrorMessage(ERR_MUST_SPECIFY_USERNAME.Error(), time.Time{}, http.StatusBadRequest, nil)
	}
	if len(errors) > 0 {
		return apiutil.OutputErrorMessage("Value errors. See result", errors, http.StatusBadRequest, nil)
	}
	if err != nil {
		return apiutil.OutputErrorMessage(err.Error(), time.Time{}, http.StatusInternalServerError, nil)
	}
	cxt.SetResult(obj)
	return 0, nil, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:33,代码来源:set_password.go

示例10: ReadAccessToken

func (p *facebookClient) ReadAccessToken(body string, now time.Time) error {
	params, err := url.ParseQuery(body)
	if err != nil {
		s := jsonhelper.NewJSONObject()
		if err2 := json.Unmarshal([]byte(body), &s); err2 != nil {
			LogError("Unable to read error response: ", body)
			return err2
		}
		return errors.New(fmt.Sprintf("%v", s))
	}
	if params == nil {
		params = make(url.Values)
	}
	t := &facebookAccessTokenResult{accessToken: params.Get("access_token")}
	if len(params.Get("expires")) > 0 {
		expiresIn, _ := strconv.ParseInt(params.Get("expires"), 10, 64)
		if expiresIn >= 0 {
			t.expiresAt = time.Unix(now.Unix()+expiresIn, 0).UTC()
		}
	}
	if len(t.accessToken) > 0 {
		p.expiresAt = t.expiresAt
		p.accessToken = t.accessToken
	}
	return nil

}
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:27,代码来源:facebook.go

示例11: HandleInputHandlerAfterSetup

func (p *ViewContactRequestHandler) HandleInputHandlerAfterSetup(cxt ViewContactContext) (int, http.Header, io.WriterTo) {
	obj := jsonhelper.NewJSONObject()
	contactObj, _ := jsonhelper.Marshal(cxt.Contact())
	obj.Set("contact", contactObj)
	obj.Set("type", "contact")
	cxt.SetResult(obj)
	return 0, nil, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:8,代码来源:view.go

示例12: TestCreateUserAccount

func TestCreateUserAccount(t *testing.T) {
	ds := inmemory.NewInMemoryDataStore()
	wm := webmachine.NewWebMachine()
	wm.AddRouteHandler(account.NewCreateAccountRequestHandler(ds, ds))
	buf := bytes.NewBufferString(`{"role": 9999999999999999, "name": "George Washington", "username": "firstpresident", "email":"[email protected]", "phone_number": "+1-405-555-5555", "address": "Valley Forge"}`)
	oldUser := new(dm.User)
	json.Unmarshal(buf.Bytes(), &oldUser)
	req, _ := http.NewRequest(webmachine.POST, "http://localhost/api/v1/json/account/user/create/", buf)
	req.Header.Set("Content-Type", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
	req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
	req.Header.Set("Accept-Charset", "utf-8")
	req.Header.Set("Accept-Encoding", "identity")
	req.Header.Set("Accept-Language", "en-us")
	req.Header.Set("Connection", "close")
	resp := webmachine.NewMockResponseWriter(req)
	reqb, _ := httputil.DumpRequest(req, true)
	wm.ServeHTTP(resp, req)
	if resp.StatusCode != 200 {
		t.Error("Expected 200 status code but received ", resp.StatusCode)
	}
	if resp.Header().Get("Content-Type") != req.Header.Get("Accept") {
		t.Error("Expected Content-Type \"", req.Header.Get("Accept"), "\" but received ", resp.Header().Get("Content-Type"))
	}
	user := new(dm.User)
	obj := jsonhelper.NewJSONObject()
	err := json.Unmarshal(resp.Buffer.Bytes(), &obj)
	user.InitFromJSONObject(obj.GetAsObject("result").GetAsObject("user"))
	if err != nil {
		t.Error("Error while unmarshaling JSON: ", err.Error())
	}
	if obj.GetAsString("status") != "success" {
		t.Error("Expected status = \"success\", but was \"", obj.GetAsString("status"), "\"")
	}
	if user.Name != oldUser.Name {
		t.Logf("Request was\n%s\n================\n", string(reqb))
		t.Log("Response is:\n", resp.String(), "\n\n")
		t.Error("Expected name = \"", oldUser.Name, "\", but was ", user.Name)
	}
	if user.Username != oldUser.Username {
		t.Error("Expected username = \"", oldUser.Username, "\", but was ", user.Username)
	}
	if user.Email != oldUser.Email {
		t.Error("Expected email = \"", oldUser.Email, "\", but was ", user.Email)
	}
	if user.PhoneNumber != oldUser.PhoneNumber {
		t.Error("Expected phone_number = \"", oldUser.PhoneNumber, "\", but was ", user.PhoneNumber)
	}
	if user.Address != oldUser.Address {
		t.Error("Expected address = \"", oldUser.Address, "\", but was ", user.Address)
	}
	if user.Role != dm.ROLE_STANDARD {
		t.Error("Expected role = ", dm.ROLE_STANDARD, " but was ", user.Role)
	}
	if user.Id == "" {
		t.Error("Expected id to be populated, but was empty")
	}
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:57,代码来源:create_test.go

示例13: HandleGenericOauthRequest

func HandleGenericOauthRequest(c oauth2_client.OAuth2Client, w http.ResponseWriter, req *http.Request) {
	uri := c.GenerateRequestTokenUrl(jsonhelper.NewJSONObject())
	if len(uri) > 0 {
		w.Header().Set("Location", uri)
		w.WriteHeader(302)
	} else {
		w.WriteHeader(500)
	}
}
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:9,代码来源:oauth2_client_tester.go

示例14: TestAuthLoginNoUsername

func TestAuthLoginNoUsername(t *testing.T) {
	_, wm := initializeAuthUserAccountDS()
	jsonobj := jsonhelper.NewJSONObject()
	jsonobj.Set("password", "number two")
	jsonbuf, _ := json.Marshal(jsonobj)
	req, _ := http.NewRequest(webmachine.POST, "http://localhost/api/v1/json/auth/login/", bytes.NewBuffer(jsonbuf))
	req.Header.Set("Content-Type", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
	req.Header.Set("Accept", webmachine.MIME_TYPE_JSON+"; charset=utf-8")
	req.Header.Set("Accept-Charset", "utf-8")
	req.Header.Set("Accept-Encoding", "identity")
	req.Header.Set("Accept-Language", "en-us")
	req.Header.Set("Connection", "close")
	reqbytes, _ := httputil.DumpRequest(req, true)
	t.Log("Request is:\n", string(reqbytes), "\n\n")
	resp := webmachine.NewMockResponseWriter(req)
	wm.ServeHTTP(resp, req)
	t.Log("Response is:\n", resp.String(), "\n\n")
	if resp.StatusCode != http.StatusUnauthorized {
		t.Error("Expected ", http.StatusUnauthorized, " status code but received ", resp.StatusCode)
	}
	if resp.Header().Get("Content-Type") != req.Header.Get("Accept") {
		t.Error("Expected Content-Type \"", req.Header.Get("Accept"), "\" but received ", resp.Header().Get("Content-Type"))
	}
	obj := jsonhelper.NewJSONObject()
	err := json.Unmarshal(resp.Buffer.Bytes(), &obj)
	if err != nil {
		t.Error("Unable to unmarshal login response due to error:", err.Error())
	}
	if status := obj.GetAsString("status"); status != "error" {
		t.Error("Expected error operation, but had status:", status)
	}
	result := obj.GetAsObject("result")
	if result.Len() != 1 {
		t.Error("Expected a result object with 1 entry, but has", result.Len(), "entries as:", result)
	}
	if username := result.GetAsArray("username"); len(username) != 1 || username[0] != auth.ERR_MUST_SPECIFY_USERNAME.Error() {
		t.Error("Expected one error for missing username, but was", result)
	}
	if message := obj.GetAsString("message"); message != auth.ERR_VALUE_ERRORS.Error() {
		t.Error("Expected ERR_VALUE_ERRORS for message, but was", message)
	}
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:42,代码来源:login_test.go

示例15: HandleInitialClientRedirect

func HandleInitialClientRedirect(w http.ResponseWriter, req *http.Request) {
	client := oauth2_client.NewGoogleClient()
	client.Initialize(settings)
	tokenUrl := client.GenerateRequestTokenUrl(jsonhelper.NewJSONObject())
	if len(tokenUrl) > 0 {
		w.Header().Set("Location", tokenUrl)
		w.WriteHeader(302)
	} else {
		w.WriteHeader(500)
	}
}
开发者ID:pomack,项目名称:oauth2_client.go,代码行数:11,代码来源:example.go


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