當前位置: 首頁>>代碼示例>>Golang>>正文


Golang errs.Format函數代碼示例

本文整理匯總了Golang中github.com/ungerik/go-start/errs.Format函數的典型用法代碼示例。如果您正苦於以下問題:Golang Format函數的具體用法?Golang Format怎麽用?Golang Format使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Format函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: subDocumentType

func (self *Collection) subDocumentType(docType reflect.Type, fieldName string, subDocSelectors []string) (reflect.Type, error) {
	if fieldName == "" {
		return docType, errs.Format("Collection '%s', selector '%s': Empty field name", self.Name, strings.Join(subDocSelectors, "."))
	}

	switch docType.Kind() {
	case reflect.Struct:
		bsonName := strings.ToLower(fieldName)
		field := reflection.FindFlattenedStructField(docType, MatchBsonField(bsonName))
		if field != nil {
			return field.Type, nil
		}
		return nil, errs.Format("Collection '%s', selector '%s': Struct has no field '%s'", self.Name, strings.Join(subDocSelectors, "."), fieldName)

	case reflect.Array, reflect.Slice:
		_, numberErr := strconv.Atoi(fieldName)
		if numberErr == nil || fieldName == "$" {
			return docType, nil
		}
		return docType.Elem(), nil

	case reflect.Ptr, reflect.Interface:
		return self.subDocumentType(docType.Elem(), fieldName, subDocSelectors)
	}

	return nil, errs.Format("Collection '%s', selector '%s': Can't select sub-document '%s' of type '%s'", self.Name, strings.Join(subDocSelectors, "."), fieldName, docType.String())
}
開發者ID:JessonChan,項目名稱:go-start,代碼行數:27,代碼來源:collection.go

示例2: Collection

func (self *Ref) Collection() (collection *Collection, err error) {
	if self.CollectionName == "" {
		return nil, errs.Format("Missing collection name. Did you call mongo.Document.Init()?")
	}
	collection, ok := collections[self.CollectionName]
	if !ok {
		return nil, errs.Format("Collection '" + self.CollectionName + "' not registered")
	}
	return collection, nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:10,代碼來源:ref.go

示例3: Collection

func (self *Ref) Collection() *Collection {
	if self.CollectionName == "" {
		panic(errs.Format("Missing collection name. Did you call mongo.Document.Init()?"))
	}
	collection, ok := Collections[self.CollectionName]
	if !ok {
		panic(errs.Format("Collection '" + self.CollectionName + "' not registered"))
	}
	return collection
}
開發者ID:JessonChan,項目名稱:go-start,代碼行數:10,代碼來源:ref.go

示例4: Save

func (self *SubDocumentBase) Save() error {
	if self.embeddingStruct == nil {
		return errs.Format("Can't save uninitialized mongo.SubDocument. embeddingStruct is nil.")
	}
	if !self.rootDocumentID.Valid() {
		return errs.Format("Can't save mongo.SubDocument with invalid RootDocumentObjectId.")
	}

	return self.collection.Update(self.rootDocumentID, bson.M{self.selector: self.embeddingStruct})
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:10,代碼來源:subdocumentbase.go

示例5: Validate

func (self *Ref) Validate(metaData *model.MetaData) error {
	if self.CollectionName == "" {
		return errs.Format("Missing CollectionName")
	}
	length := len(self.ID)
	if length != 0 && length != 12 {
		return errs.Format("Invalid ObjectId length %d", length)
	}
	if self.Required(metaData) && self.IsEmpty() {
		return model.NewRequiredError(metaData)
	}
	return nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:13,代碼來源:ref.go

示例6: References

func (self *Ref) References(doc Document) (ok bool, err error) {
	collection := doc.Collection()
	if collection == nil {
		return false, errs.Format("Document is not initialized")
	}
	if collection.Name != self.CollectionName {
		return false, errs.Format("mongo.Ref to collection '%s' can't reference document of collection '%s'", self.CollectionName, collection.Name)
	}
	id := doc.ObjectId()
	if !id.Valid() {
		return false, errs.Format("Can't reference document with empty ID")
	}
	return self.ID == id, nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:14,代碼來源:ref.go

示例7: documentWithID

func (self *Collection) documentWithID(id bson.ObjectId, subDocSelectors ...string) (document interface{}, err error) {
	if len(subDocSelectors) > 0 {
		panic("Sub document selectors are not implemented")
	}
	if id == "" {
		return nil, errs.Format("mongo.Collection %s: Can't get document with empty id", self.Name)
	}
	if err = self.ValidateSelector(subDocSelectors...); err != nil {
		return nil, err
	}

	self.checkDBConnection()
	document = self.NewDocument(subDocSelectors...)
	q := self.collection.Find(bson.M{"_id": id})
	if len(subDocSelectors) == 0 {
		err = q.One(document)
	} else {
		err = q.Select(strings.Join(subDocSelectors, ".")).One(document)
	}
	if err != nil {
		return nil, err
	}
	// document has to be initialized again,
	// because mgo zeros the struct while unmarshalling.
	// Newly created slice elements need to be initialized too
	self.InitDocument(document)
	return document, nil
}
開發者ID:JessonChan,項目名稱:go-start,代碼行數:28,代碼來源:collection.go

示例8: Render

func (self *Video) Render(context *Context, writer *utils.XMLWriter) (err error) {
	youtubeId := ""

	switch {
	case strings.HasPrefix(self.URL, "http://youtu.be/"):
		i := len("http://youtu.be/")
		youtubeId = self.URL[i : i+11]

	case strings.HasPrefix(self.URL, "http://www.youtube.com/watch?v="):
		i := len("http://www.youtube.com/watch?v=")
		youtubeId = self.URL[i : i+11]
	}

	if youtubeId != "" {
		writer.OpenTag("iframe").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
		width := self.Width
		if width == 0 {
			width = 640
		}
		height := self.Height
		if height == 0 {
			height = 390
		}
		writer.Attrib("src", "http://www.youtube.com/embed/", youtubeId)
		writer.Attrib("width", width)
		writer.Attrib("height", height)
		writer.Attrib("frameborder", "0")
		writer.Attrib("allowfullscreen", "allowfullscreen")
		writer.CloseTag()
		return nil
	}

	return errs.Format("Unsupported video URL: %s", self.URL)
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:34,代碼來源:video.go

示例9: From

func From(document interface{}) (user *User) {
	v := reflect.ValueOf(document)

	// Dereference pointers until we have a struct value
	for v.Kind() == reflect.Ptr {
		if v.IsNil() {
			return nil
		}
		v = v.Elem()
	}

	if v.Kind() == reflect.Struct {
		if v.Type() == UserType {
			return v.Addr().Interface().(*User)
		}

		count := v.NumField()
		for i := 0; i < count; i++ {
			field := v.Field(i)
			if field.Type() == UserType {
				return field.Addr().Interface().(*User)
			}
		}
	}

	panic(errs.Format("user.From(): invalid document type %T", document))
}
開發者ID:JessonChan,項目名稱:go-start,代碼行數:27,代碼來源:functions.go

示例10: Validate

func (self *MultipleChoice) Validate(metaData *MetaData) error {
	options := self.Options(metaData)
	if len(options) == 0 {
		return errs.Format("model.MultipleChoice needs options")
	}
	for _, option := range options {
		if option == "" {
			return errs.Format("model.MultipleChoice options must not be empty strings")
		}
	}
	for _, str := range *self {
		if !utils.StringIn(str, options) {
			return &InvalidChoice{str, options}
		}
	}
	return nil
}
開發者ID:JessonChan,項目名稱:go-start,代碼行數:17,代碼來源:multiplechoice.go

示例11: Limit

func (self *queryBase) Limit(limit int) Query {
	if limit < 0 {
		return &QueryError{self.ParentQuery(), errs.Format("Invalid negative limit: %d", limit)}
	}
	q := &limitQuery{limit: limit}
	q.init(q, self.thisQuery)
	return q
}
開發者ID:JessonChan,項目名稱:go-start,代碼行數:8,代碼來源:querybase.go

示例12: Skip

func (self *queryBase) Skip(skip int) Query {
	if skip < 0 {
		return &QueryError{self.ParentQuery(), errs.Format("Invalid negative skip count: %d", skip)}
	}
	q := &skipQuery{skip: skip}
	q.init(q, self.thisQuery)
	return q
}
開發者ID:JessonChan,項目名稱:go-start,代碼行數:8,代碼來源:querybase.go

示例13: Or

func (self *queryBase) Or() Query {
	if !self.thisQuery.IsFilter() {
		return &QueryError{self.thisQuery, errs.Format("Or() can only be called after Filter()")}
	}
	q := &orQuery{}
	q.init(q, self.thisQuery)
	return q
}
開發者ID:JessonChan,項目名稱:go-start,代碼行數:8,代碼來源:querybase.go

示例14: Delete

func (self *CookieSessionDataStore) Delete(context *Context) (err error) {
	sessionID, ok := context.SessionID()
	if !ok {
		return errs.Format("Can't delete session data without a session id")
	}

	context.SetSecureCookie(self.cookieName(sessionID), "", -time.Now().Unix(), "/")
	return nil
}
開發者ID:sedzinreri,項目名稱:go-start,代碼行數:9,代碼來源:sessiondatastore.go

示例15: Delete

func (self *CookieSessionDataStore) Delete(ctx *Context) (err error) {
	sessionID := ctx.Session.ID()
	if sessionID == "" {
		return errs.Format("Can't delete session data without a session id")
	}

	ctx.Response.SetSecureCookie(self.cookieName(sessionID), "", -time.Now().Unix(), "/")
	return nil
}
開發者ID:prinsmike,項目名稱:go-start,代碼行數:9,代碼來源:sessiondatastore.go


注:本文中的github.com/ungerik/go-start/errs.Format函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。