本文整理汇总了Golang中github.com/CloudCom/firego.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: updateView
func updateView(pid, uid string) {
if isRelevantTo(pid, uid) {
now := time.Now()
p := firego.New(userPostsURL + "/" + uid + "/" + pid)
p.Set(now)
p = firego.New(postUsersURL + "/" + pid + "/" + uid)
p.Set(now)
}
}
示例2: putPostNode
func putPostNode(id string, p *PostNode) error {
fb := firego.New(postsURL + "/" + id)
if err := fb.Set(p); err != nil {
return err
}
return nil
}
示例3: SignIn
// SignIn creates the user's posts view and starts the user's notification
// channel.
func SignIn(uid, name, imageUrl string) error {
un := UserNode{Name: name, ImageURL: imageUrl}
if err := putUserNode(uid, &un); err != nil {
return err
}
// for right now, every user is watching every post
fb := firego.New(userPostsURL + "/" + uid)
fb.Set(nil)
qns, err := getPostNodes(QuestionType)
if err != nil {
return err
}
for pid := range qns {
updateView(pid, uid)
}
c := make(chan firego.Event)
if err := fb.Watch(c); err != nil {
return err
}
// TODO: this needs to be protected by a mutex
userNotifications[uid] = c
return nil
}
示例4: ExampleFirebase_IncludePriority
func ExampleFirebase_IncludePriority() {
fb := firego.New("https://someapp.firebaseio.com")
// turn on
fb.IncludePriority(true)
// turn off
fb.IncludePriority(false)
}
示例5: ExampleFirebase_Shallow
func ExampleFirebase_Shallow() {
fb := firego.New("https://someapp.firebaseio.com")
// turn on
fb.Shallow(true)
// turn off
fb.Shallow(false)
}
示例6: CustomerHandler
func CustomerHandler(response http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request)
customer := vars["customer"]
orderId := vars["order"]
f := firego.New("https://example-app-123.firebaseio.com")
f.Auth("<FIREBASE KEY>")
var profileBuffer bytes.Buffer
profileBuffer.WriteString("/customers/")
profileBuffer.WriteString(customer)
profileBuffer.WriteString("/profile/")
var orderBuffer bytes.Buffer
orderBuffer.WriteString("/customers/")
orderBuffer.WriteString(customer)
orderBuffer.WriteString("/orders/")
orderBuffer.WriteString(orderId)
profile := f.Child(profileBuffer.String())
var p Profile
if err := profile.Value(&p); err != nil {
log.Fatal(err)
}
order := f.Child(orderBuffer.String())
var o Order
if err := order.Value(&o); err != nil {
log.Fatal(err)
}
if _, err := Mailer(p, o); err != nil {
log.Fatal(err)
}
}
示例7: getPostNode
func getPostNode(id string) (*PostNode, error) {
fb := firego.New(postsURL + "/" + id)
v := &PostNode{}
if err := fb.Value(v); err != nil {
return nil, err
}
return v, nil
}
示例8: getCommentNode
func getCommentNode(id string) (*CommentNode, error) {
fb := firego.New(commentsURL + "/" + id)
v := &CommentNode{}
if err := fb.Value(v); err != nil {
return nil, err
}
return v, nil
}
示例9: NewAPI
func NewAPI(fbURL, fbSecret string) (*api, error) {
if fbURL == "" || fbSecret == "" {
return nil, errors.New("fbURL or fbSecret are empty")
}
fb := firego.New(fbURL)
fb.Auth(fbSecret)
return &api{fb: fb}, nil
}
示例10: getQuestionNode
func getQuestionNode(id string) (*QuestionNode, error) {
fb := firego.New(questionsURL + "/" + id)
v := &QuestionNode{}
if err := fb.Value(v); err != nil {
return nil, err
}
return v, nil
}
示例11: getUser
// getUser returns a User given a UID. Note that it never returns an error;
// if a user isn't found, the User returned will have the zero value.
func getUser(uid string) User {
fb := firego.New(usersURL + "/" + uid)
var v UserNode
if err := fb.Value(&v); err != nil {
return User{}
}
return User{UID: uid, Name: v.Name, ImageURL: v.ImageURL}
}
示例12: getAnswerNode
func getAnswerNode(id string) (*AnswerNode, error) {
fb := firego.New(answersURL + "/" + id)
v := &AnswerNode{}
if err := fb.Value(v); err != nil {
return nil, err
}
return v, nil
}
示例13: ExampleFirebase_Value
func ExampleFirebase_Value() {
fb := firego.New("https://someapp.firebaseio.com/some/value")
var v interface{}
if err := fb.Value(v); err != nil {
log.Fatal(err)
}
log.Printf("My value %v\n", v)
}
示例14: ExampleFirebase_Push
func ExampleFirebase_Push() {
fb := firego.New("https://someapp.firebaseio.com")
newRef, err := fb.Push("my-value")
if err != nil {
log.Fatal(err)
}
log.Printf("My new ref %s\n", newRef)
}
示例15: addPostNode
func addPostNode(uid string, t PostType) (string, error) {
fb := firego.New(postsURL)
p := PostNode{Type: t, Added: time.Now(), AddedBy: uid}
n, err := fb.Push(p)
if err != nil {
return "", err
}
path := strings.Split(n.String(), "/")
return path[len(path)-1], nil
}