本文整理匯總了Golang中github.com/flynn/flynn/pkg/postgres.CleanUUID函數的典型用法代碼示例。如果您正苦於以下問題:Golang CleanUUID函數的具體用法?Golang CleanUUID怎麽用?Golang CleanUUID使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CleanUUID函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Add
func (r *ReleaseRepo) Add(data interface{}) error {
release := data.(*ct.Release)
releaseCopy := *release
releaseCopy.ID = ""
releaseCopy.ArtifactID = ""
releaseCopy.CreatedAt = nil
for typ, proc := range releaseCopy.Processes {
resource.SetDefaults(&proc.Resources)
releaseCopy.Processes[typ] = proc
}
data, err := json.Marshal(&releaseCopy)
if err != nil {
return err
}
if release.ID == "" {
release.ID = random.UUID()
}
var artifactID *string
if release.ArtifactID != "" {
artifactID = &release.ArtifactID
}
err = r.db.QueryRow("INSERT INTO releases (release_id, artifact_id, data) VALUES ($1, $2, $3) RETURNING created_at",
release.ID, artifactID, data).Scan(&release.CreatedAt)
release.ID = postgres.CleanUUID(release.ID)
if release.ArtifactID != "" {
release.ArtifactID = postgres.CleanUUID(release.ArtifactID)
}
return err
}
示例2: Add
func (r *ReleaseRepo) Add(data interface{}) error {
release := data.(*ct.Release)
releaseCopy := *release
releaseCopy.ID = ""
releaseCopy.ArtifactID = ""
releaseCopy.CreatedAt = nil
for typ, proc := range releaseCopy.Processes {
resource.SetDefaults(&proc.Resources)
releaseCopy.Processes[typ] = proc
}
data, err := json.Marshal(&releaseCopy)
if err != nil {
return err
}
if release.ID == "" {
release.ID = random.UUID()
}
var artifactID *string
if release.ArtifactID != "" {
artifactID = &release.ArtifactID
}
tx, err := r.db.Begin()
if err != nil {
return err
}
err = tx.QueryRow("INSERT INTO releases (release_id, artifact_id, data) VALUES ($1, $2, $3) RETURNING created_at",
release.ID, artifactID, data).Scan(&release.CreatedAt)
if err != nil {
tx.Rollback()
return err
}
release.ID = postgres.CleanUUID(release.ID)
if release.ArtifactID != "" {
release.ArtifactID = postgres.CleanUUID(release.ArtifactID)
}
if err := createEvent(tx.Exec, &ct.Event{
ObjectID: release.ID,
ObjectType: ct.EventTypeRelease,
}, release); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
示例3: scanJobEvent
func scanJobEvent(s postgres.Scanner) (*ct.JobEvent, error) {
event := &ct.JobEvent{}
err := s.Scan(&event.ID, &event.JobID, &event.AppID, &event.ReleaseID, &event.Type, &event.State, &event.CreatedAt)
if err != nil {
if err == sql.ErrNoRows {
err = ErrNotFound
}
return nil, err
}
event.AppID = postgres.CleanUUID(event.AppID)
event.ReleaseID = postgres.CleanUUID(event.ReleaseID)
return event, nil
}
示例4: Add
func (r *DeploymentRepo) Add(data interface{}) error {
d := data.(*ct.Deployment)
if d.ID == "" {
d.ID = random.UUID()
}
var oldReleaseID *string
if d.OldReleaseID != "" {
oldReleaseID = &d.OldReleaseID
}
procs := procsHstore(d.Processes)
tx, err := r.db.Begin()
if err != nil {
return err
}
query := "INSERT INTO deployments (deployment_id, app_id, old_release_id, new_release_id, strategy, processes) VALUES ($1, $2, $3, $4, $5, $6) RETURNING created_at"
if err := tx.QueryRow(query, d.ID, d.AppID, oldReleaseID, d.NewReleaseID, d.Strategy, procs).Scan(&d.CreatedAt); err != nil {
tx.Rollback()
return err
}
d.ID = postgres.CleanUUID(d.ID)
d.AppID = postgres.CleanUUID(d.AppID)
d.OldReleaseID = postgres.CleanUUID(d.OldReleaseID)
d.NewReleaseID = postgres.CleanUUID(d.NewReleaseID)
// fake initial deployment
if d.FinishedAt != nil {
if _, err := tx.Exec("UPDATE deployments SET finished_at = $2 WHERE deployment_id = $1", d.ID, d.FinishedAt); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
if err := tx.Commit(); err != nil {
return err
}
args, err := json.Marshal(ct.DeployID{ID: d.ID})
if err != nil {
return err
}
// TODO: wrap all of this in a transaction once we move to pgx
if err := r.q.Enqueue(&que.Job{
Type: "deployment",
Args: args,
}); err != nil {
return err
}
return nil
}
示例5: Add
func (r *ProviderRepo) Add(data interface{}) error {
p := data.(*ct.Provider)
if p.Name == "" {
return errors.New("controller: name must not be blank")
}
if p.URL == "" {
return errors.New("controler: url must not be blank")
}
// TODO: validate url
tx, err := r.db.Begin()
if err != nil {
return err
}
err = tx.QueryRow("INSERT INTO providers (name, url) VALUES ($1, $2) RETURNING provider_id, created_at, updated_at", p.Name, p.URL).Scan(&p.ID, &p.CreatedAt, &p.UpdatedAt)
if err != nil {
tx.Rollback()
return err
}
p.ID = postgres.CleanUUID(p.ID)
if err := createEvent(tx.Exec, &ct.Event{
ObjectID: p.ID,
ObjectType: ct.EventTypeProvider,
}, p); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}
示例6: scanArtifact
func scanArtifact(s postgres.Scanner) (*ct.Artifact, error) {
artifact := &ct.Artifact{}
err := s.Scan(&artifact.ID, &artifact.Type, &artifact.URI, &artifact.CreatedAt)
if err == sql.ErrNoRows {
err = ErrNotFound
}
artifact.ID = postgres.CleanUUID(artifact.ID)
return artifact, err
}
示例7: scanProvider
func scanProvider(s postgres.Scanner) (*ct.Provider, error) {
p := &ct.Provider{}
err := s.Scan(&p.ID, &p.Name, &p.URL, &p.CreatedAt, &p.UpdatedAt)
if err == sql.ErrNoRows {
err = ErrNotFound
}
p.ID = postgres.CleanUUID(p.ID)
return p, err
}
示例8: streamRouterEvents
func streamRouterEvents(rc routerc.Client, db *postgres.DB, doneCh chan struct{}) error {
// wait for router to come up
{
events := make(chan *discoverd.Event)
stream, err := discoverd.NewService("router-api").Watch(events)
if err != nil {
return err
}
for e := range events {
if e.Kind == discoverd.EventKindUp {
break
}
}
stream.Close()
}
events := make(chan *router.StreamEvent)
s, err := rc.StreamEvents(events)
if err != nil {
return err
}
go func() {
for {
e, ok := <-events
if !ok {
return
}
route := e.Route
route.ID = postgres.CleanUUID(route.ID)
var appID string
if strings.HasPrefix(route.ParentRef, routeParentRefPrefix) {
appID = strings.TrimPrefix(route.ParentRef, routeParentRefPrefix)
}
eventType := ct.EventTypeRoute
if e.Event == "remove" {
eventType = ct.EventTypeRouteDeletion
}
hash := md5.New()
io.WriteString(hash, appID)
io.WriteString(hash, string(eventType))
io.WriteString(hash, route.ID)
io.WriteString(hash, route.CreatedAt.String())
io.WriteString(hash, route.UpdatedAt.String())
uniqueID := fmt.Sprintf("%x", hash.Sum(nil))
if err := createEvent(wrapDBExec(db.Exec), &ct.Event{
AppID: appID,
ObjectID: route.ID,
ObjectType: eventType,
UniqueID: uniqueID,
}, route); err != nil {
log.Println(err)
}
}
}()
_, _ = <-doneCh
return s.Close()
}
示例9: Add
func (r *AppRepo) Add(data interface{}) error {
app := data.(*ct.App)
tx, err := r.db.Begin()
if err != nil {
return err
}
if app.Name == "" {
var nameID uint32
if err := tx.QueryRow("SELECT nextval('name_ids')").Scan(&nameID); err != nil {
tx.Rollback()
return err
}
app.Name = name.Get(nameID)
}
if len(app.Name) > 100 || !appNamePattern.MatchString(app.Name) {
return ct.ValidationError{Field: "name", Message: "is invalid"}
}
if app.ID == "" {
app.ID = random.UUID()
}
if app.Strategy == "" {
app.Strategy = "all-at-once"
}
meta := metaToHstore(app.Meta)
if err := tx.QueryRow("INSERT INTO apps (app_id, name, meta, strategy) VALUES ($1, $2, $3, $4) RETURNING created_at, updated_at", app.ID, app.Name, meta, app.Strategy).Scan(&app.CreatedAt, &app.UpdatedAt); err != nil {
tx.Rollback()
if postgres.IsUniquenessError(err, "apps_name_idx") {
return httphelper.ObjectExistsErr(fmt.Sprintf("application %q already exists", app.Name))
}
return err
}
app.ID = postgres.CleanUUID(app.ID)
if err := createEvent(tx.Exec, &ct.Event{
AppID: app.ID,
ObjectID: app.ID,
ObjectType: ct.EventTypeApp,
}, app); err != nil {
tx.Rollback()
return err
}
if err := tx.Commit(); err != nil {
return err
}
if !app.System() && r.defaultDomain != "" {
route := (&router.HTTPRoute{
Domain: fmt.Sprintf("%s.%s", app.Name, r.defaultDomain),
Service: app.Name + "-web",
}).ToRoute()
if err := createRoute(r.db, r.router, app.ID, route); err != nil {
log.Printf("Error creating default route for %s: %s", app.Name, err)
}
}
return nil
}
示例10: scanRelease
func scanRelease(s postgres.Scanner) (*ct.Release, error) {
var artifactID *string
release := &ct.Release{}
var data []byte
err := s.Scan(&release.ID, &artifactID, &data, &release.CreatedAt)
if err != nil {
if err == sql.ErrNoRows {
err = ErrNotFound
}
return nil, err
}
if artifactID != nil {
release.ArtifactID = *artifactID
}
release.ID = postgres.CleanUUID(release.ID)
release.ArtifactID = postgres.CleanUUID(release.ArtifactID)
err = json.Unmarshal(data, release)
return release, err
}
示例11: scanJob
func scanJob(s postgres.Scanner) (*ct.Job, error) {
job := &ct.Job{}
var meta hstore.Hstore
err := s.Scan(&job.ID, &job.AppID, &job.ReleaseID, &job.Type, &job.State, &meta, &job.CreatedAt, &job.UpdatedAt)
if err != nil {
if err == sql.ErrNoRows {
err = ErrNotFound
}
return nil, err
}
if len(meta.Map) > 0 {
job.Meta = make(map[string]string, len(meta.Map))
for k, v := range meta.Map {
job.Meta[k] = v.String
}
}
job.AppID = postgres.CleanUUID(job.AppID)
job.ReleaseID = postgres.CleanUUID(job.ReleaseID)
return job, nil
}
示例12: scanDeployment
func scanDeployment(s postgres.Scanner) (*ct.Deployment, error) {
d := &ct.Deployment{}
var procs hstore.Hstore
err := s.Scan(&d.ID, &d.AppID, &d.OldReleaseID, &d.NewReleaseID, &d.Strategy, &procs, &d.CreatedAt, &d.FinishedAt)
if err == sql.ErrNoRows {
err = ErrNotFound
}
d.Processes = make(map[string]int, len(procs.Map))
for k, v := range procs.Map {
n, _ := strconv.Atoi(v.String)
if n > 0 {
d.Processes[k] = n
}
}
d.ID = postgres.CleanUUID(d.ID)
d.AppID = postgres.CleanUUID(d.AppID)
d.OldReleaseID = postgres.CleanUUID(d.OldReleaseID)
d.NewReleaseID = postgres.CleanUUID(d.NewReleaseID)
return d, err
}
示例13: scanApp
func scanApp(s postgres.Scanner) (*ct.App, error) {
app := &ct.App{}
var meta hstore.Hstore
var releaseID *string
err := s.Scan(&app.ID, &app.Name, &meta, &app.Strategy, &releaseID, &app.CreatedAt, &app.UpdatedAt)
if err == sql.ErrNoRows {
err = ErrNotFound
}
if releaseID != nil {
app.ReleaseID = postgres.CleanUUID(*releaseID)
}
if len(meta.Map) > 0 {
app.Meta = make(map[string]string, len(meta.Map))
for k, v := range meta.Map {
app.Meta[k] = v.String
}
}
app.ID = postgres.CleanUUID(app.ID)
return app, err
}
示例14: scanFormation
func scanFormation(s postgres.Scanner) (*ct.Formation, error) {
f := &ct.Formation{}
var procs hstore.Hstore
err := s.Scan(&f.AppID, &f.ReleaseID, &procs, &f.CreatedAt, &f.UpdatedAt)
if err != nil {
if err == sql.ErrNoRows {
err = ErrNotFound
}
return nil, err
}
f.Processes = make(map[string]int, len(procs.Map))
for k, v := range procs.Map {
n, _ := strconv.Atoi(v.String)
if n > 0 {
f.Processes[k] = n
}
}
f.AppID = postgres.CleanUUID(f.AppID)
f.ReleaseID = postgres.CleanUUID(f.ReleaseID)
return f, nil
}
示例15: Add
func (r *ProviderRepo) Add(data interface{}) error {
p := data.(*ct.Provider)
if p.Name == "" {
return errors.New("controller: name must not be blank")
}
if p.URL == "" {
return errors.New("controler: url must not be blank")
}
// TODO: validate url
err := r.db.QueryRow("INSERT INTO providers (name, url) VALUES ($1, $2) RETURNING provider_id, created_at, updated_at", p.Name, p.URL).Scan(&p.ID, &p.CreatedAt, &p.UpdatedAt)
p.ID = postgres.CleanUUID(p.ID)
return err
}