1 Star 0 Fork 0

litian/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util.go 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
Nathan LeClaire 提交于 2016-11-15 15:20 . Fix golint errors
package azureutil
import (
"fmt"
"math/rand"
"strings"
"time"
)
/* Utilities */
// randomAzureStorageAccountName generates a valid storage account name prefixed
// with a predefined string. Availability of the name is not checked. Uses maximum
// length to maximise randomness.
func randomAzureStorageAccountName() string {
const (
maxLen = 24
chars = "0123456789abcdefghijklmnopqrstuvwxyz"
)
return storageAccountPrefix + randomString(maxLen-len(storageAccountPrefix), chars)
}
// randomString generates a random string of given length using specified alphabet.
func randomString(n int, alphabet string) string {
r := timeSeed()
b := make([]byte, n)
for i := range b {
b[i] = alphabet[r.Intn(len(alphabet))]
}
return string(b)
}
// imageName holds various components of an OS image name identifier
type imageName struct{ publisher, offer, sku, version string }
// parseImageName parses a publisher:offer:sku:version into those parts.
func parseImageName(image string) (imageName, error) {
l := strings.Split(image, ":")
if len(l) != 4 {
return imageName{}, fmt.Errorf("image name %q not a valid format", image)
}
return imageName{l[0], l[1], l[2], l[3]}, nil
}
func timeSeed() *rand.Rand { return rand.New(rand.NewSource(time.Now().UTC().UnixNano())) }
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/litian33/machine.git
git@gitee.com:litian33/machine.git
litian33
machine
machine
v0.15.0-rancher1

搜索帮助

0d507c66 1850385 C8b1a773 1850385