コード例 #1
0
ファイル: uuid.go プロジェクト: jmptrader/ogo
// generate uuid v5
// namespace直接写域名或者url
func NewUUID5(namespace, data string) string {
	//以http开头的为URL, 其余都为DNS
	if strings.HasPrefix(strings.ToLower(namespace), "http") {
		//return gouuid.NewV5(uuid.NameSpace_URL, []byte(namespace+data)).String()
		u5, _ := gouuid.NewV5(gouuid.NamespaceURL, []byte(namespace+data))
		return u5.String()
	} else {
		//return uuid.NewSHA1(uuid.NameSpace_DNS, []byte(namespace+data)).String()
		u5, _ := gouuid.NewV5(gouuid.NamespaceDNS, []byte(namespace+data))
		return u5.String()
	}
}
コード例 #2
0
ファイル: job.go プロジェクト: carriercomm/docker-builder
/*
NewJob creates a new job from the config as well as a job spec.  After creating
the job, calling job.Process() will actually perform the work.
*/
func NewJob(cfg *Config, spec *Spec, req *http.Request) *Job {
	var idUUID *gouuid.UUID
	var err error
	idUUID, err = gouuid.NewV4()
	if TestMode {
		idUUID, err = gouuid.NewV5(gouuid.NamespaceURL, []byte("0"))
	}

	if err != nil {
		cfg.Logger.WithField("error", err).Error("error creating uuid")
	}
	id := idUUID.String()

	bobfile := spec.Bobfile
	if bobfile == "" {
		bobfile = defaultBobfile
	}

	ret := &Job{
		Bobfile:        bobfile,
		ID:             id,
		Account:        spec.RepoOwner,
		GitHubAPIToken: spec.GitHubAPIToken,
		Ref:            spec.GitRef,
		Repo:           spec.RepoName,
		Workdir:        cfg.Workdir,
		InfoRoute:      "/jobs/" + id,
		LogRoute:       "/jobs/" + id + "/tail?n=" + defaultTail,
		logDir:         cfg.Workdir + "/" + id,
		Status:         "created",
		Created:        time.Now(),
	}
	ret.addHostToRoutes(req)

	out, file, err := newMultiWriter(ret.logDir)
	if err != nil {
		cfg.Logger.WithField("error", err).Error("error creating log dir")
		id = ""
	}

	ret.logFile = file
	ret.Logger = &logrus.Logger{
		Formatter: cfg.Logger.Formatter,
		Level:     cfg.Logger.Level,
		Out:       out,
	}

	if ret.GitHubAPIToken == "" {
		ret.GitHubAPIToken = cfg.GitHubAPIToken
	}

	if id != "" {
		jobs[id] = ret
	}

	return ret
}