您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)golang中g(shù)olang-id2code-code2id的示例分析,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
package service import "strings" var ( idcode_words = []string{ "F", "6", "G", "7", "H", "J", "K", "R", "S", "T", "U", "V", "W", "X", "L", "8", "M", "9", "N", "P", "Q", "A", "3", "B", "5", "C", "D", "E", } ) type idcode struct { BaseNum int64 StepNum uint Wrods []string } func (this *idcode) Code(id int64) string { str := "" words_len := len(this.Wrods) id = (id + this.BaseNum) << this.StepNum for ; id > 0; id /= int64(words_len) { str = this.Wrods[id%int64(words_len)] + str } return str } func (this *idcode) Id(code string) int64 { var id int64 words_len := len(this.Wrods) arr := strings.Split(code, "") for _, word := range arr { for j, __word := range this.Wrods { if word == __word { id = id*int64(words_len) + int64(j) break } } } return (id >> this.StepNum) - this.BaseNum } func Id2Code(id int64) string { return (&idcode{BaseNum: 9999, StepNum: 19, Wrods: idcode_words}).Code(id) } func Code2Id(code string) int64 { return (&idcode{BaseNum: 9999, StepNum: 19, Wrods: idcode_words}).Id(code) }
關(guān)于“golang中g(shù)olang-id2code-code2id的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。