本文整理汇总了Golang中github.com/twinj/uuid.Formatter函数的典型用法代码示例。如果您正苦于以下问题:Golang Formatter函数的具体用法?Golang Formatter怎么用?Golang Formatter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Formatter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: InsertPost
func InsertPost(title []byte, slug string, markdown []byte, html []byte, featured bool, isPage bool, published bool, image []byte, created_at time.Time, created_by int64) (int64, error) {
status := "draft"
if published {
status = "published"
}
writeDB, err := readDB.Begin()
if err != nil {
writeDB.Rollback()
return 0, err
}
var result sql.Result
if published {
result, err = writeDB.Exec(stmtInsertPost, nil, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), title, slug, markdown, html, featured, isPage, status, image, created_by, created_at, created_by, created_at, created_by, created_at, created_by)
} else {
result, err = writeDB.Exec(stmtInsertPost, nil, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), title, slug, markdown, html, featured, isPage, status, image, created_by, created_at, created_by, created_at, created_by, nil, nil)
}
if err != nil {
writeDB.Rollback()
return 0, err
}
postId, err := result.LastInsertId()
if err != nil {
writeDB.Rollback()
return 0, err
}
return postId, writeDB.Commit()
}
示例2: NewEntry
func NewEntry() *Entry {
id := uuid.NewV4()
return &Entry{
uuid: strings.ToUpper(uuid.Formatter(id, uuid.Clean)), // e.g. FF755C6D7D9B4A5FBC4E41C07D622C65
}
}
示例3: NewNode
func NewNode(controllerUrl string, dockerUrl string, tlsConfig *tls.Config, cpus float64, memory float64, heartbeatInterval int, ip string, showOnlyGridContainers bool, enableDebug bool) (*Node, error) {
if enableDebug {
log.SetLevel(log.DebugLevel)
}
u := uuid.NewV4()
id := uuid.Formatter(u, uuid.CleanHyphen)
client, err := dockerclient.NewDockerClient(dockerUrl, tlsConfig)
if err != nil {
return nil, err
}
node := &Node{
Id: id,
client: client,
controllerUrl: controllerUrl,
heartbeatInterval: heartbeatInterval,
showOnlyGridContainers: showOnlyGridContainers,
ip: ip,
Cpus: cpus,
Memory: memory,
}
return node, nil
}
示例4: Initialize
func Initialize() error {
// If journey.db does not exist, look for a Ghost database to convert
if !helpers.FileExists(filenames.DatabaseFilename) {
// Convert Ghost database if available (time format needs to change to be compatible with journey)
migration.Ghost()
}
// Open or create database file
var err error
readDB, err = sql.Open("sqlite3", filenames.DatabaseFilename)
if err != nil {
return err
}
readDB.SetMaxIdleConns(256) // TODO: is this enough?
err = readDB.Ping()
if err != nil {
return err
}
currentTime := time.Now()
_, err = readDB.Exec(stmtInitialization, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), currentTime, currentTime)
// TODO: Is Commit()/Rollback() needed for DB.Exec()?
if err != nil {
return err
}
err = checkBlogSettings()
if err != nil {
return err
}
return nil
}
示例5: saveImage
func saveImage(image string) (string, error) {
if image == "" {
return "", nil
}
var number = uuid.NewV4()
var newImage = "download/" + uuid.Formatter(number, uuid.CurlyHyphen)
out, error := os.Create(newImage)
if error != nil {
return "", error
}
defer out.Close()
response, error := http.Get(image)
if error != nil {
return "", error
}
defer response.Body.Close()
pix, error := ioutil.ReadAll(response.Body)
if error != nil {
return "", error
}
_, error = io.Copy(out, bytes.NewReader(pix))
if error != nil {
return "", error
}
return newImage, nil
}
示例6: GuidHandler
func GuidHandler(w http.ResponseWriter, r *http.Request) {
id := uuid.NewV4()
containerId, _ := os.Hostname()
guidReponse := GuidReponse{}
guidReponse.Guid = uuid.Formatter(id, uuid.FormatCanonicalCurly)
guidReponse.ContainerId = containerId
jsonValue, _ := json.Marshal(guidReponse)
w.Write([]byte(jsonValue))
}
示例7: insertSettingInt64
func insertSettingInt64(key string, value int64, setting_type string, created_at time.Time, created_by int64) error {
writeDB, err := readDB.Begin()
if err != nil {
writeDB.Rollback()
return err
}
_, err = writeDB.Exec(stmtInsertSetting, nil, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), key, value, setting_type, created_at, created_by, created_at, created_by)
if err != nil {
writeDB.Rollback()
return err
}
return writeDB.Commit()
}
示例8: ApiUsersRegister
func ApiUsersRegister(r *http.Request, enc encoder.Encoder, store Store) (int, []byte) {
if r.URL.Query().Get("email") != "" && r.URL.Query().Get("password") != "" {
db := GetDbSession()
user := User{ID: uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen), Email: r.URL.Query().Get("email"), Password: sha1Password(r.URL.Query().Get("password")), Token: uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen)}
err := db.Insert(&user)
if err != nil {
log.Println(err)
return http.StatusBadRequest, encoder.Must(enc.Encode(err))
}
log.Printf("Registering new user with email %s, password: %s , userid:%s, token:%s", user.Email, user.Password, user.ID, user.Token)
return http.StatusOK, encoder.Must(enc.Encode(user))
}
return http.StatusBadRequest, encoder.Must(enc.Encode("Missing email param"))
}
示例9: NewClient
func NewClient(base string, contextType string) *Client {
client := snooze.Client{
Root: "http://" + base,
Before: func(r *http.Request, c *http.Client) {
c.Timeout = 0
},
}
result := new(Client)
result.Root = base
result.ContextType = contextType
result.Process = uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen)
client.Create(&result.API)
return result
}
示例10: InsertTag
func InsertTag(name []byte, slug string, created_at time.Time, created_by int64) (int64, error) {
writeDB, err := readDB.Begin()
if err != nil {
writeDB.Rollback()
return 0, err
}
result, err := writeDB.Exec(stmtInsertTag, nil, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), name, slug, created_at, created_by, created_at, created_by)
if err != nil {
writeDB.Rollback()
return 0, err
}
tagId, err := result.LastInsertId()
if err != nil {
writeDB.Rollback()
return 0, err
}
return tagId, writeDB.Commit()
}
示例11: InsertUser
func InsertUser(name []byte, slug string, password string, email []byte, image []byte, cover []byte, created_at time.Time, created_by int64) (int64, error) {
writeDB, err := readDB.Begin()
if err != nil {
writeDB.Rollback()
return 0, err
}
result, err := writeDB.Exec(stmtInsertUser, nil, uuid.Formatter(uuid.NewV4(), uuid.FormatCanonical), name, slug, password, email, image, cover, created_at, created_by, created_at, created_by)
if err != nil {
writeDB.Rollback()
return 0, err
}
userId, err := result.LastInsertId()
if err != nil {
writeDB.Rollback()
return 0, err
}
return userId, writeDB.Commit()
}
示例12: CreateTodoItem
// Create a Todo item
// Returns the id of the new item, or an error on failure
func (dbm *DatabaseManager) CreateTodoItem(item *TodoItem) (string, error) {
//Generate a UUID for this new Todo item
id := uuid.Formatter(uuid.NewV4(), uuid.Clean)
//Fill in some values
nowTime := time.Now().UTC()
item.Created = nowTime
item.Type = "todo_item"
//validate
if !item.Validate() {
return "", &couchdb.Error{
StatusCode: 400,
Reason: "TodoItem is invalid",
}
}
//Save it to the database
if _, err := dbm.db.Save(item, id, ""); err != nil {
return "", err
} else {
return id, nil
}
}
示例13: Example
func Example() {
var config = uuid.StateSaverConfig{SaveReport: true, SaveSchedule: 30 * time.Minute}
uuid.SetupFileSystemStateSaver(config)
u1 := uuid.NewV1()
fmt.Printf("version %d variant %x: %s\n", u1.Version(), u1.Variant(), u1)
uP, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
u3 := uuid.NewV3(uP, uuid.Name("test"))
u4 := uuid.NewV4()
fmt.Printf("version %d variant %x: %s\n", u4.Version(), u4.Variant(), u4)
u5 := uuid.NewV5(uuid.NamespaceURL, uuid.Name("test"))
if uuid.Equal(u1, u3) {
fmt.Printf("Will never happen")
}
fmt.Printf(uuid.Formatter(u5, uuid.CurlyHyphen))
uuid.SwitchFormat(uuid.BracketHyphen)
}
示例14: ApiFilesPost
func ApiFilesPost(r *http.Request, enc encoder.Encoder, store Store, parms martini.Params) (int, []byte) {
db := GetDbSession()
token := r.Header.Get("X-API-TOKEN")
user := User{}
err := db.SelectOne(&user, "select * from users where token=?", token)
if err != nil {
return http.StatusUnauthorized, encoder.Must(enc.Encode(
NewError(ErrCodeNotExist, "Error")))
}
var userFiles []UserFile
body, _ := ioutil.ReadAll(r.Body)
r.Body.Close()
err = json.Unmarshal(body, &userFiles)
if err != nil {
return http.StatusNotFound, encoder.Must(enc.Encode(
NewError(ErrCodeNotExist, "Could not decode body")))
}
for userFile_i, userFile := range userFiles {
err = db.SelectOne(&userFiles[userFile_i], "select * from users_files where user_id=? and relative_path=?", userFile.UserID, userFile.RelativePath)
if err == sql.ErrNoRows {
userFiles[userFile_i].ID = uuid.Formatter(uuid.NewV4(), uuid.CleanHyphen)
userFiles[userFile_i].UserID = user.ID
db.Insert(&userFiles[userFile_i])
// TODO Error
} else if err != nil {
// TODO Error
}
}
//Temp call for testing
go func(userId string) {
ApiProcessFiles(userId)
}(user.ID)
return http.StatusOK, encoder.Must(enc.Encode(userFiles))
}
示例15: Example
func Example() {
saver := new(savers.FileSystemSaver)
saver.Report = true
saver.Duration = time.Second * 3
// Run before any v1 or v2 UUIDs to ensure the savers takes
uuid.RegisterSaver(saver)
up, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
fmt.Printf("version %d variant %x: %s\n", up.Version(), up.Variant(), up)
uuid.New(up.Bytes())
u1 := uuid.NewV1()
fmt.Printf("version %d variant %x: %s\n", u1.Version(), u1.Variant(), u1)
u4 := uuid.NewV4()
fmt.Printf("version %d variant %x: %s\n", u4.Version(), u4.Variant(), u4)
u3 := uuid.NewV3(u1, u4)
url, _ := url.Parse("www.example.com")
u5 := uuid.NewV5(uuid.NameSpaceURL, url)
if uuid.Equal(u1, u3) {
fmt.Println("Will never happen")
}
if uuid.Compare(uuid.NameSpaceDNS, uuid.NameSpaceDNS) == 0 {
fmt.Println("They are equal")
}
// Default Format is Canonical
fmt.Println(uuid.Formatter(u5, uuid.FormatCanonicalCurly))
uuid.SwitchFormat(uuid.FormatCanonicalBracket)
}