• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang uuid.Formatter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/twinj/uuid.Formatter函数的典型用法代码示例。如果您正苦于以下问题:Golang Formatter函数的具体用法?Golang Formatter怎么用?Golang Formatter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Formatter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
}
开发者ID:itkpi,项目名称:journey,代码行数:28,代码来源:insertion.go


示例2: NewEntry

func NewEntry() *Entry {
	id := uuid.NewV4()

	return &Entry{
		uuid: strings.ToUpper(uuid.Formatter(id, uuid.Clean)), // e.g. FF755C6D7D9B4A5FBC4E41C07D622C65
	}
}
开发者ID:booyaa,项目名称:go-dayone,代码行数:7,代码来源:entry.go


示例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
}
开发者ID:carriercomm,项目名称:docker-grid,代码行数:25,代码来源:node.go


示例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
}
开发者ID:itkpi,项目名称:journey,代码行数:29,代码来源:initialization.go


示例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
}
开发者ID:fishedee,项目名称:GoSample,代码行数:31,代码来源:main.go


示例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))
}
开发者ID:alexellis,项目名称:docker-arm,代码行数:10,代码来源:main.go


示例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()
}
开发者ID:itkpi,项目名称:journey,代码行数:13,代码来源:insertion.go


示例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"))
}
开发者ID:geoah,项目名称:42minutes-server-api,代码行数:14,代码来源:apiUsers.go


示例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
}
开发者ID:ironbay,项目名称:jarvis-go,代码行数:14,代码来源:client.go


示例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()
}
开发者ID:itkpi,项目名称:journey,代码行数:18,代码来源:insertion.go


示例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()
}
开发者ID:itkpi,项目名称:journey,代码行数:18,代码来源:insertion.go


示例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
	}
}
开发者ID:rhinoman,项目名称:simple-todo,代码行数:23,代码来源:database.go


示例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)
}
开发者ID:lovedboy,项目名称:tidb,代码行数:22,代码来源:uuid_test.go


示例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))
}
开发者ID:geoah,项目名称:42minutes-server-api,代码行数:39,代码来源:apiFiles.go


示例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)
}
开发者ID:antha-lang,项目名称:manualLiquidHandler,代码行数:38,代码来源:examples_test.go


示例16: apiUploadHandler

// API function to upload images
func apiUploadHandler(w http.ResponseWriter, r *http.Request, _ map[string]string) {
	userName := authentication.GetUserName(r)
	if userName != "" {
		// Create multipart reader
		reader, err := r.MultipartReader()
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		// Slice to hold all paths to the files
		allFilePaths := make([]string, 0)
		// Copy each part to destination.
		for {
			part, err := reader.NextPart()
			if err == io.EOF {
				break
			}
			// If part.FileName() is empty, skip this iteration.
			if part.FileName() == "" {
				continue
			}
			// Folder structure: year/month/randomname
			filePath := filepath.Join(filenames.ImagesFilepath, time.Now().Format("2006"), time.Now().Format("01"))
			if os.MkdirAll(filePath, 0777) != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			dst, err := os.Create(filepath.Join(filePath, strconv.FormatInt(time.Now().Unix(), 10)+"_"+uuid.Formatter(uuid.NewV4(), uuid.Clean)+filepath.Ext(part.FileName())))
			defer dst.Close()
			if err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			if _, err := io.Copy(dst, part); err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			// Rewrite to file path on server
			filePath = strings.Replace(dst.Name(), filenames.ImagesFilepath, "/images", 1)
			// Make sure to always use "/" as path separator (to make a valid url that we can use on the blog)
			filePath = filepath.ToSlash(filePath)
			allFilePaths = append(allFilePaths, filePath)
		}
		json, err := json.Marshal(allFilePaths)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		w.Header().Set("Content-Type", "application/json")
		w.Write(json)
		return
	} else {
		http.Error(w, "Not logged in!", http.StatusInternalServerError)
		return
	}
}
开发者ID:troyxmccall,项目名称:goblahg,代码行数:57,代码来源:admin.go


示例17: GenUuid

func GenUuid() string {
	return uuid.Formatter(uuid.NewV4(), uuid.Clean)
}
开发者ID:rhinoman,项目名称:wikifeat,代码行数:3,代码来源:database.go


示例18: ExampleFormatter

func ExampleFormatter() {
	u4 := uuid.NewV4()
	fmt.Println(uuid.Formatter(u4, uuid.FormatCanonicalCurly))
}
开发者ID:antha-lang,项目名称:manualLiquidHandler,代码行数:4,代码来源:examples_test.go


示例19:

	. "github.com/onsi/gomega"
	"github.com/twinj/uuid"
)

var _ = Describe("Core", func() {

	Describe("DeviceFile", func() {
		It("should implement DeviceFile", func() {
			var f DeviceFile
			f = &HardwareFile{}
			Ω(f).ShouldNot(BeNil())
		})
		It("should read/write to a real file", func() {
			f := HardwareFile{}
			u4 := uuid.NewV4()
			name := uuid.Formatter(u4, uuid.Clean)
			tmp := path.Join(os.TempDir(), name+".gotest.tmp")

			By("using tmp " + tmp)
			// Write to the file
			err := f.Write(tmp, "Hello World")
			Ω(err).Should(BeNil())
			// Read and verify file
			text, err := f.Read(tmp)
			Ω(err).Should(BeNil())
			Ω(text).Should(Equal("Hello World"))
			// Test file existence directly
			found, err := ioutil.ReadFile(tmp)
			Ω(err).Should(BeNil())
			Ω(found).Should(Equal([]byte("Hello World")))
			// Clean up
开发者ID:gopackage,项目名称:sysfs,代码行数:31,代码来源:sysfs_test.go


示例20: getUuid

func getUuid() string {
	theUuid := uuid.NewV4()
	return uuid.Formatter(theUuid, uuid.Clean)
}
开发者ID:PyYoshi,项目名称:couchdb-go,代码行数:4,代码来源:couchdb_test.go



注:本文中的github.com/twinj/uuid.Formatter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang uuid.NewV4函数代码示例发布时间:2022-05-28
下一篇:
Golang weavebox.Context类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap