dongliangkeng1056 2017-03-20 11:44
浏览 181
已采纳

如何使用Golang为Firebase创建推送ID?

i want to push a map to firebase with an id (eg:-KfKoScgRhylaLjQlK-y)

fitToWorkMap := make(map[string]models.TaskFitToWork)
    fitToWorkForTask :=models.TaskFitToWork{}
    for i := 0; i < len(FitToWorkSlice); i++ {
        fitToWorkForTask.Info =FitToWorkSlice[i]
        fitToWorkForTask.DateOfCreation =time.Now().Unix()
        fitToWorkForTask.Status = helpers.StatusPending

        fitToWorkMap["fgsgdsfn+'i'"] = fitToWorkForTask
    }
    task.FitToWork = fitToWorkMap

here fitToWorkMap is a map .i want to generate a key for this map

  • 写回答

1条回答 默认 最新

  • dpwh11290 2017-03-20 14:16
    关注

    Those keys starting with -K are called push IDs and they are automatically generated by Firebase:

    There is no Firebase SDK for Go and uses the REST API to interact with the Firebase Database. That means that it only generates a push ID when it POSTs a new node to the database. I don't know of any library for Go to generate Firebase push IDs client-side.

    But luckily the keys are quite well documented in a blog post. The code for a JavaScript implementation of generatePushID() is also available, so you could port that over to Go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?