本文整理汇总了Golang中github.com/pomack/jsonhelper/go/jsonhelper.MarshalWithOptions函数的典型用法代码示例。如果您正苦于以下问题:Golang MarshalWithOptions函数的具体用法?Golang MarshalWithOptions怎么用?Golang MarshalWithOptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MarshalWithOptions函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Encode
func (p *InMemoryDataStore) Encode(w io.Writer) os.Error {
v, err := jsonhelper.MarshalWithOptions(p, dm.UTC_DATETIME_FORMAT)
if err != nil {
return err
}
return json.NewEncoder(w).Encode(v)
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:7,代码来源:datastore.go
示例2: ContentTypesProvided
func (p *GeneratePrivateKeyRequestHandler) ContentTypesProvided(req wm.Request, cxt wm.Context) ([]wm.MediaTypeHandler, wm.Request, wm.Context, int, error) {
gpkc := cxt.(GeneratePrivateKeyContext)
user := gpkc.User()
consumer := gpkc.Consumer()
var userId, consumerId string
if user != nil {
userId = user.Id
}
if consumer != nil {
consumerId = consumer.Id
}
accessKey, err := p.authDS.StoreAccessKey(dm.NewAccessKey(userId, consumerId))
gpkc.SetAccessKey(accessKey)
obj := make(map[string]interface{})
if user != nil {
obj["user_id"] = user.Id
obj["username"] = user.Username
obj["name"] = user.Name
}
if consumer != nil {
obj["consumer_id"] = consumer.Id
obj["consumer_short_name"] = consumer.ShortName
}
if accessKey != nil {
obj["access_key_id"] = accessKey.Id
obj["private_key"] = accessKey.PrivateKey
}
theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
jsonObj, _ := theobj.(jsonhelper.JSONObject)
if err != nil {
return []wm.MediaTypeHandler{apiutil.NewJSONMediaTypeHandler(jsonObj, time.Time{}, "")}, req, gpkc, http.StatusInternalServerError, err
}
return []wm.MediaTypeHandler{apiutil.NewJSONMediaTypeHandler(jsonObj, time.Time{}, "")}, req, gpkc, 0, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:34,代码来源:generate_private_key.go
示例3: createJSONHttpResponseFromObj
func createJSONHttpResponseFromObj(req *http.Request, obj interface{}) (resp *http.Response, err error) {
var b []byte
if obj != nil {
obj1, _ := jsonhelper.MarshalWithOptions(obj, GOOGLE_DATETIME_FORMAT)
jsonobj := obj1.(jsonhelper.JSONObject)
b, err = json.Marshal(jsonobj)
}
if b == nil {
b = make([]byte, 0)
}
buf := bytes.NewBuffer(b)
headers := make(http.Header)
headers.Add("Content-Type", "application/json; charset=utf-8")
resp = new(http.Response)
resp.Status = "200 OK"
resp.StatusCode = http.StatusOK
resp.Proto = "HTTP/1.1"
resp.ProtoMajor = 1
resp.ProtoMinor = 1
resp.Header = headers
resp.Body = ioutil.NopCloser(buf)
resp.ContentLength = int64(len(b))
resp.TransferEncoding = []string{"identity"}
resp.Close = true
resp.Request = req
return
}
开发者ID:pomack,项目名称:contacts.go,代码行数:27,代码来源:mock.go
示例4: HandleJSONObjectInputHandler
func (p *UpdateAccountRequestHandler) HandleJSONObjectInputHandler(req wm.Request, cxt wm.Context, inputObj jsonhelper.JSONObject) (int, http.Header, io.WriterTo) {
uac := cxt.(UpdateAccountContext)
uac.SetFromJSON(inputObj)
uac.CleanInput(uac.RequestingUser(), uac.OriginalValue())
//log.Print("[UARH]: HandleJSONObjectInputHandler()")
errors := make(map[string][]error)
var obj interface{}
var err error
ds := p.ds
switch uac.Type() {
case "user":
if user := uac.User(); user != nil {
//log.Printf("[UARH]: user is not nil1: %v\n", user)
user.Validate(false, errors)
if len(errors) == 0 {
user, err = ds.UpdateUserAccount(user)
//log.Printf("[UARH]: user after errors is %v\n", user)
}
obj = user
uac.SetUser(user)
//log.Printf("[UARH]: setUser to %v\n", user)
}
case "consumer":
if user := uac.Consumer(); user != nil {
user.Validate(false, errors)
if len(errors) == 0 {
user, err = ds.UpdateConsumerAccount(user)
}
obj = user
uac.SetConsumer(user)
}
case "external_user":
if user := uac.ExternalUser(); user != nil {
user.Validate(false, errors)
if len(errors) == 0 {
user, err = ds.UpdateExternalUserAccount(user)
}
obj = user
uac.SetExternalUser(user)
}
default:
return apiutil.OutputErrorMessage("\"type\" must be \"user\", \"consumer\", or \"external_user\"", nil, 400, nil)
}
if len(errors) > 0 {
return apiutil.OutputErrorMessage("Value errors. See result", errors, http.StatusBadRequest, nil)
}
if err != nil {
return apiutil.OutputErrorMessage(err.Error(), nil, http.StatusInternalServerError, nil)
}
theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
jsonObj, _ := theobj.(jsonhelper.JSONObject)
//log.Printf("[UARH]: obj was: \n%v\n", obj)
//log.Printf("[UARH]: Going to output:\n%s\n", jsonObj)
return apiutil.OutputJSONObject(jsonObj, uac.LastModified(), uac.ETag(), http.StatusOK, nil)
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:55,代码来源:update.go
示例5: HandleJSONObjectInputHandler
func (p *ViewAccountRequestHandler) HandleJSONObjectInputHandler(req wm.Request, cxt wm.Context, inputObj jsonhelper.JSONObject) (int, http.Header, io.WriterTo) {
vac := cxt.(ViewAccountContext)
obj := vac.ToObject()
var err error
if err != nil {
return apiutil.OutputErrorMessage(err.Error(), nil, http.StatusInternalServerError, nil)
}
theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
jsonObj, _ := theobj.(jsonhelper.JSONObject)
return apiutil.OutputJSONObject(jsonObj, vac.LastModified(), vac.ETag(), 0, nil)
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:12,代码来源:view.go
示例6: ContentTypesProvided
func (p *ViewAccountRequestHandler) ContentTypesProvided(req wm.Request, cxt wm.Context) ([]wm.MediaTypeHandler, wm.Request, wm.Context, int, error) {
vac := cxt.(ViewAccountContext)
obj := vac.ToObject()
lastModified := vac.LastModified()
etag := vac.ETag()
var jsonObj jsonhelper.JSONObject
if obj != nil {
theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
jsonObj, _ = theobj.(jsonhelper.JSONObject)
}
return []wm.MediaTypeHandler{apiutil.NewJSONMediaTypeHandler(jsonObj, lastModified, etag)}, req, vac, 0, nil
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:12,代码来源:view.go
示例7: HandleJSONObjectInputHandler
func (p *DeleteAccountRequestHandler) HandleJSONObjectInputHandler(req wm.Request, cxt wm.Context, inputObj jsonhelper.JSONObject) (int, http.Header, io.WriterTo) {
dac := cxt.(DeleteAccountContext)
obj := dac.ToObject()
var err error
if !dac.Deleted() {
_, req, cxt, _, err = p.DeleteResource(req, cxt)
}
if err != nil {
return apiutil.OutputErrorMessage(err.Error(), nil, http.StatusInternalServerError, nil)
}
theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
jsonObj, _ := theobj.(jsonhelper.JSONObject)
return apiutil.OutputJSONObject(jsonObj, time.Time{}, "", 0, nil)
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:15,代码来源:delete.go
示例8: Decode
func (p *InMemoryDataStore) Decode(r io.Reader) os.Error {
err := json.NewDecoder(r).Decode(p)
if err != nil {
return err
}
m := make(map[string]interface{})
m[_INMEMORY_CONTACT_COLLECTION_NAME] = new(dm.Contact)
m[_INMEMORY_CONNECTION_COLLECTION_NAME] = new(dm.Contact)
m[_INMEMORY_GROUP_COLLECTION_NAME] = new(dm.Group)
m[_INMEMORY_CHANGESET_COLLECTION_NAME] = new(dm.ChangeSet)
m[_INMEMORY_CONTACT_FOR_EXTERNAL_CONTACT_COLLECTION_NAME] = new(dm.Contact)
m[_INMEMORY_GROUP_FOR_EXTERNAL_GROUP_COLLECTION_NAME] = new(dm.Group)
// These three have different types based on the service
//m[_INMEMORY_EXTERNAL_CONTACT_COLLECTION_NAME] = "external_contacts"
//m[_INMEMORY_EXTERNAL_GROUP_COLLECTION_NAME] = "external_group"
//m[_INMEMORY_USER_TO_CONTACT_SETTINGS_COLLECTION_NAME] = "user_to_contact_settings"
// These four are all strings
//m[_INMEMORY_EXTERNAL_TO_INTERNAL_CONTACT_MAPPING_COLLECTION_NAME] = ""
//m[_INMEMORY_INTERNAL_TO_EXTERNAL_CONTACT_MAPPING_COLLECTION_NAME] = ""
//m[_INMEMORY_EXTERNAL_TO_INTERNAL_GROUP_MAPPING_COLLECTION_NAME] = ""
//m[_INMEMORY_INTERNAL_TO_EXTERNAL_GROUP_MAPPING_COLLECTION_NAME] = ""
m[_INMEMORY_CHANGESETS_TO_APPLY_COLLECTION_NAME] = new(dm.ChangeSetsToApply)
m[_INMEMORY_CHANGESETS_NOT_CURRENTLY_APPLYABLE_COLLECTION_NAME] = new(dm.ChangeSetsToApply)
for k, collection := range p.Collections {
for k1, v1 := range collection.Data {
m1, _ := jsonhelper.MarshalWithOptions(v1, dm.UTC_DATETIME_FORMAT)
b1, _ := json.Marshal(m1)
if obj, ok := m[k]; ok {
err = json.Unmarshal(b1, obj)
if err != nil {
return err
}
collection.Data[k1] = obj
} else {
collection.Data[k1] = b1
}
}
}
return nil
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:41,代码来源:datastore.go
示例9: HandleJSONObjectInputHandler
func (p *CreateAccountRequestHandler) HandleJSONObjectInputHandler(req wm.Request, cxt wm.Context, writer io.Writer, inputObj jsonhelper.JSONObject) (int, http.Header, os.Error) {
cac := cxt.(CreateAccountContext)
cac.SetFromJSON(inputObj)
cac.CleanInput(cac.RequestingUser())
errors := make(map[string][]os.Error)
var obj interface{}
var err os.Error
ds := p.ds
if user := cac.User(); user != nil {
user.Validate(true, errors)
if len(errors) == 0 {
user, err = ds.CreateUserAccount(user)
}
obj = user
} else if user := cac.Consumer(); user != nil {
user.Validate(true, errors)
if len(errors) == 0 {
user, err = ds.CreateConsumerAccount(user)
}
obj = user
} else if user := cac.ExternalUser(); user != nil {
user.Validate(true, errors)
if len(errors) == 0 {
user, err = ds.CreateExternalUserAccount(user)
}
obj = user
} else {
return apiutil.OutputErrorMessage(writer, "\"type\" must be \"user\", \"consumer\", or \"external_user\"", nil, 400, nil)
}
if len(errors) > 0 {
return apiutil.OutputErrorMessage(writer, "Value errors. See result", errors, http.StatusBadRequest, nil)
}
if err != nil {
return apiutil.OutputErrorMessage(writer, err.String(), nil, http.StatusInternalServerError, nil)
}
theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
jsonObj, _ := theobj.(jsonhelper.JSONObject)
return apiutil.OutputJSONObject(writer, jsonObj, cac.LastModified(), cac.ETag(), 0, nil)
}
开发者ID:pombredanne,项目名称:dsocial.go,代码行数:40,代码来源:create.go
示例10: HandleJSONObjectInputHandler
func (p *CreateAccountRequestHandler) HandleJSONObjectInputHandler(req wm.Request, cxt wm.Context, inputObj jsonhelper.JSONObject) (int, http.Header, io.WriterTo) {
cac := cxt.(CreateAccountContext)
cac.SetFromJSON(inputObj)
cac.CleanInput(cac.RequestingUser())
errors := make(map[string][]error)
var obj map[string]interface{}
var accessKey *dm.AccessKey
var err error
ds := p.ds
authDS := p.authDS
if user := cac.User(); user != nil {
var userPassword *dm.UserPassword
user.Validate(true, errors)
if len(errors) == 0 {
user, err = ds.CreateUserAccount(user)
if err == nil && user != nil {
accessKey, err = authDS.StoreAccessKey(dm.NewAccessKey(user.Id, ""))
}
}
if cac.Password() != "" && user != nil && user.Id != "" {
userPassword = dm.NewUserPassword(user.Id, cac.Password())
userPassword.Validate(true, errors)
if len(errors) == 0 && err == nil {
userPassword, err = authDS.StoreUserPassword(userPassword)
}
}
obj = make(map[string]interface{})
obj["user"] = user
obj["type"] = "user"
obj["key"] = accessKey
} else if user := cac.Consumer(); user != nil {
user.Validate(true, errors)
if len(errors) == 0 {
user, err = ds.CreateConsumerAccount(user)
if err == nil && user != nil {
accessKey, err = authDS.StoreAccessKey(dm.NewAccessKey("", user.Id))
}
}
obj = make(map[string]interface{})
obj["consumer"] = user
obj["type"] = "consumer"
obj["key"] = accessKey
} else if user := cac.ExternalUser(); user != nil {
user.Validate(true, errors)
if len(errors) == 0 {
user, err = ds.CreateExternalUserAccount(user)
if err == nil && user != nil {
accessKey, err = authDS.StoreAccessKey(dm.NewAccessKey(user.Id, user.ConsumerId))
}
}
obj = make(map[string]interface{})
obj["external_user"] = user
obj["type"] = "external_user"
obj["key"] = accessKey
} else {
return apiutil.OutputErrorMessage("\"type\" must be \"user\", \"consumer\", or \"external_user\"", nil, 400, nil)
}
if len(errors) > 0 {
return apiutil.OutputErrorMessage("Value errors. See result", errors, http.StatusBadRequest, nil)
}
if err != nil {
return apiutil.OutputErrorMessage(err.Error(), nil, http.StatusInternalServerError, nil)
}
theobj, _ := jsonhelper.MarshalWithOptions(obj, dm.UTC_DATETIME_FORMAT)
jsonObj, _ := theobj.(jsonhelper.JSONObject)
return apiutil.OutputJSONObject(jsonObj, cac.LastModified(), cac.ETag(), 0, nil)
}
开发者ID:pomack,项目名称:dsocial.go,代码行数:68,代码来源:create.go
注:本文中的github.com/pomack/jsonhelper/go/jsonhelper.MarshalWithOptions函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论