本文整理汇总了Golang中github.com/ungerik/go-start/errs.Format函数的典型用法代码示例。如果您正苦于以下问题:Golang Format函数的具体用法?Golang Format怎么用?Golang Format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Format函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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)
}
if ok, err := self.CheckID(); !ok {
if err != nil {
return err
}
return errs.Format("Invalid mongo.Ref. No document with ID %s in collection %s", self.ID, self.CollectionName)
}
return nil
}
开发者ID:JessonChan,项目名称:go-start,代码行数:19,代码来源:ref.go
示例17: Init
func (self *Configuration) Init() error {
if self.initialized {
panic("view.Config already initialized")
}
if !self.IsProductionServer {
addrs, err := net.InterfaceAddrs()
if err != nil {
return err
}
for _, addr := range addrs {
if ipNet, ok := addr.(*net.IPNet); ok {
ip := ipNet.IP.String()
for _, prodIP := range Config.ProductionServerIPs {
if ip == prodIP {
self.IsProductionServer = true
break
}
}
}
}
}
if !self.IsProductionServer {
self.Debug.Mode = true
}
// Check if dirs exists and make them absolute
for i := range Config.BaseDirs {
dir, err := filepath.Abs(os.ExpandEnv(Config.BaseDirs[i]))
if err != nil {
return err
}
if !utils.DirExists(dir) {
return errs.Format("BaseDir does not exist: %s", dir)
}
Config.BaseDirs[i] = dir
fmt.Println("BaseDir:", dir)
}
for i := range Config.StaticDirs {
Config.StaticDirs[i] = os.ExpandEnv(Config.StaticDirs[i])
fmt.Println("StaticDir:", Config.StaticDirs[i])
}
for i := range Config.TemplateDirs {
Config.TemplateDirs[i] = os.ExpandEnv(Config.TemplateDirs[i])
fmt.Println("TemplateDir:", Config.TemplateDirs[i])
}
self.initialized = true
return nil
}
开发者ID:roleyzhang,项目名称:go-start,代码行数:54,代码来源:config.go
示例18: IndirectURL
// IndirectURL encapsulates pointers to URL implementations.
// To break circular dependencies, addresses of URL implementing variables
// can be passed to this function that encapsulates it with an URL
// implementation that dereferences the pointers at runtime.
func IndirectURL(urlPtr interface{}) URL {
switch s := urlPtr.(type) {
case **Page:
return &indirectPageURL{s}
case *ViewWithURL:
return IndirectViewWithURL(s)
case *URL:
return &indirectURL{s}
}
panic(errs.Format("%T not a pointer to a view.URL", urlPtr))
}
开发者ID:ungerik,项目名称:go-start,代码行数:15,代码来源:indirecturl.go
示例19: SetString
func (self *Ref) SetString(str string) error {
switch len(str) {
case 0, 12:
self.ID = bson.ObjectId(str)
case 24:
self.ID = bson.ObjectIdHex(str)
default:
return errs.Format("Invalid string for bson.ObjectId: '%s'", str)
}
return nil
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:11,代码来源:ref.go
示例20: Next
func (self *IndexedSliceIterator) Next(resultRef interface{}) bool {
if self.err != nil || self.index >= len(self.indices) {
return false
}
if self.indices[self.index] >= self.slice.Len() {
self.err = errs.Format("Index %d from indices greater or equal than length of slice %d", self.indices[self.index], self.slice.Len())
return false
}
reflection.SmartCopy(self.slice.Index(self.indices[self.index]), resultRef)
self.index++
return false
}
开发者ID:roleyzhang,项目名称:go-start,代码行数:12,代码来源:indexedsliceiterator.go
注:本文中的github.com/ungerik/go-start/errs.Format函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论