From 0e2f1e4e0ff078de5fdc18e96a86c0066aba1036 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 10 Jan 2022 13:31:31 +0000 Subject: [PATCH] go fmt --- api/graph/model/acl.go | 18 +++++------ api/graph/model/artifact.go | 28 ++++++++--------- api/graph/model/blob.go | 12 ++++---- api/graph/model/repository.go | 58 +++++++++++++++++------------------ api/graph/model/user.go | 20 ++++++------ api/graph/resolver.go | 2 +- api/loaders/middleware.go | 20 ++++++------ api/webhooks/webhooks.go | 6 ++-- 8 files changed, 82 insertions(+), 82 deletions(-) diff --git a/api/graph/model/acl.go b/api/graph/model/acl.go index c324bd8..1010653 100644 --- a/api/graph/model/acl.go +++ b/api/graph/model/acl.go @@ -16,8 +16,8 @@ import ( // TODO: Drop updated column from database type ACL struct { - ID int `json:"id"` - Created time.Time `json:"created"` + ID int `json:"id"` + Created time.Time `json:"created"` RawAccessMode string RepoID int @@ -54,14 +54,14 @@ func (acl *ACL) Fields() *database.ModelFields { } acl.fields = &database.ModelFields{ Fields: []*database.FieldMap{ - { "id", "id", &acl.ID }, - { "created", "created", &acl.Created }, - { "mode", "mode", &acl.RawAccessMode }, + {"id", "id", &acl.ID}, + {"created", "created", &acl.Created}, + {"mode", "mode", &acl.RawAccessMode}, // Always fetch: - { "id", "", &acl.ID }, - { "repo_id", "", &acl.RepoID }, - { "user_id", "", &acl.UserID }, + {"id", "", &acl.ID}, + {"repo_id", "", &acl.RepoID}, + {"user_id", "", &acl.UserID}, }, } return acl.fields @@ -77,7 +77,7 @@ func (acl *ACL) QueryWithCursor(ctx context.Context, if cur.Next != "" { next, _ := strconv.Atoi(cur.Next) - q = q.Where(database.WithAlias(acl.alias, "id") + "<= ?", next) + q = q.Where(database.WithAlias(acl.alias, "id")+"<= ?", next) } q = q. OrderBy(database.WithAlias(acl.alias, "id") + " DESC"). diff --git a/api/graph/model/artifact.go b/api/graph/model/artifact.go index d080500..d906d75 100644 --- a/api/graph/model/artifact.go +++ b/api/graph/model/artifact.go @@ -13,11 +13,11 @@ import ( ) type Artifact struct { - ID int `json:"id"` - Created time.Time `json:"created"` - Filename string `json:"filename"` - Checksum string `json:"checksum"` - Size int `json:"size"` + ID int `json:"id"` + Created time.Time `json:"created"` + Filename string `json:"filename"` + Checksum string `json:"checksum"` + Size int `json:"size"` Commit string @@ -44,16 +44,16 @@ func (a *Artifact) Fields() *database.ModelFields { } a.fields = &database.ModelFields{ Fields: []*database.FieldMap{ - { "id", "id", &a.ID }, - { "created", "created", &a.Created }, - { "filename", "filename", &a.Filename }, - { "checksum", "checksum", &a.Checksum }, - { "size", "size", &a.Size }, + {"id", "id", &a.ID}, + {"created", "created", &a.Created}, + {"filename", "filename", &a.Filename}, + {"checksum", "checksum", &a.Checksum}, + {"size", "size", &a.Size}, // Always fetch: - { "id", "", &a.ID }, - { "commit", "", &a.Commit }, - { "filename", "", &a.Filename }, + {"id", "", &a.ID}, + {"commit", "", &a.Commit}, + {"filename", "", &a.Filename}, }, } return a.fields @@ -69,7 +69,7 @@ func (a *Artifact) QueryWithCursor(ctx context.Context, if cur.Next != "" { next, _ := strconv.Atoi(cur.Next) - q = q.Where(database.WithAlias(a.alias, "id") + "<= ?", next) + q = q.Where(database.WithAlias(a.alias, "id")+"<= ?", next) } q = q. OrderBy(database.WithAlias(a.alias, "id") + " DESC"). diff --git a/api/graph/model/blob.go b/api/graph/model/blob.go index fd70253..21bb7e3 100644 --- a/api/graph/model/blob.go +++ b/api/graph/model/blob.go @@ -16,12 +16,12 @@ type BinaryBlob struct { Base64 string `json:"base64"` - blob *object.Blob - repo *RepoWrapper + blob *object.Blob + repo *RepoWrapper } func (BinaryBlob) IsObject() {} -func (BinaryBlob) IsBlob() {} +func (BinaryBlob) IsBlob() {} type TextBlob struct { Type ObjectType `json:"type"` @@ -31,12 +31,12 @@ type TextBlob struct { Text string `json:"text"` - blob *object.Blob - repo *RepoWrapper + blob *object.Blob + repo *RepoWrapper } func (TextBlob) IsObject() {} -func (TextBlob) IsBlob() {} +func (TextBlob) IsBlob() {} func BlobFromObject(repo *RepoWrapper, obj *object.Blob) Object { reader, err := obj.Reader() diff --git a/api/graph/model/repository.go b/api/graph/model/repository.go index cd36901..c1f6b16 100644 --- a/api/graph/model/repository.go +++ b/api/graph/model/repository.go @@ -4,28 +4,28 @@ import ( "context" "database/sql" "fmt" - "time" "strconv" + "time" + sq "github.com/Masterminds/squirrel" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" - sq "github.com/Masterminds/squirrel" "git.sr.ht/~sircmpwn/core-go/database" "git.sr.ht/~sircmpwn/core-go/model" ) type Repository struct { - ID int `json:"id"` - Created time.Time `json:"created"` - Updated time.Time `json:"updated"` - Name string `json:"name"` - Description *string `json:"description"` - UpstreamURL *string `json:"upstreamUrl"` - Readme *string `json:"readme"` - - Path string - OwnerID int + ID int `json:"id"` + Created time.Time `json:"created"` + Updated time.Time `json:"updated"` + Name string `json:"name"` + Description *string `json:"description"` + UpstreamURL *string `json:"upstreamUrl"` + Readme *string `json:"readme"` + + Path string + OwnerID int RawVisibility string alias string @@ -35,9 +35,9 @@ type Repository struct { func (r *Repository) Visibility() Visibility { visMap := map[string]Visibility{ - "public": VisibilityPublic, + "public": VisibilityPublic, "unlisted": VisibilityUnlisted, - "private": VisibilityPrivate, + "private": VisibilityPrivate, } vis, ok := visMap[r.RawVisibility] if !ok { @@ -90,20 +90,20 @@ func (r *Repository) Fields() *database.ModelFields { } r.fields = &database.ModelFields{ Fields: []*database.FieldMap{ - { "id", "id", &r.ID }, - { "created", "created", &r.Created }, - { "updated", "updated", &r.Updated }, - { "name", "name", &r.Name }, - { "description", "description", &r.Description }, - { "visibility", "visibility", &r.RawVisibility }, - { "upstream_uri", "upstreamUrl", &r.UpstreamURL }, - { "readme", "readme", &r.Readme }, + {"id", "id", &r.ID}, + {"created", "created", &r.Created}, + {"updated", "updated", &r.Updated}, + {"name", "name", &r.Name}, + {"description", "description", &r.Description}, + {"visibility", "visibility", &r.RawVisibility}, + {"upstream_uri", "upstreamUrl", &r.UpstreamURL}, + {"readme", "readme", &r.Readme}, // Always fetch: - { "id", "", &r.ID }, - { "path", "", &r.Path }, - { "owner_id", "", &r.OwnerID }, - { "updated", "", &r.Updated }, + {"id", "", &r.ID}, + {"path", "", &r.Path}, + {"owner_id", "", &r.OwnerID}, + {"updated", "", &r.Updated}, }, } return r.fields @@ -120,7 +120,7 @@ func (r *Repository) QueryWithCursor(ctx context.Context, if cur.Next != "" { ts, _ := strconv.ParseInt(cur.Next, 10, 64) updated := time.Unix(ts, 0) - q = q.Where(database.WithAlias(r.alias, "updated") + "<= ?", updated) + q = q.Where(database.WithAlias(r.alias, "updated")+"<= ?", updated) } q = q. OrderBy(database.WithAlias(r.alias, "updated") + " DESC"). @@ -160,7 +160,7 @@ func (r *Repository) DefaultSearch(query sq.SelectBuilder, desc := database.WithAlias(r.alias, "description") return query. Where(sq.Or{ - sq.Expr(name + ` ILIKE '%' || ? || '%'`, term), - sq.Expr(desc + ` ILIKE '%' || ? || '%'`, term), + sq.Expr(name+` ILIKE '%' || ? || '%'`, term), + sq.Expr(desc+` ILIKE '%' || ? || '%'`, term), }), nil } diff --git a/api/graph/model/user.go b/api/graph/model/user.go index 2e4552a..6650a32 100644 --- a/api/graph/model/user.go +++ b/api/graph/model/user.go @@ -45,18 +45,18 @@ func (u *User) Fields() *database.ModelFields { } u.fields = &database.ModelFields{ Fields: []*database.FieldMap{ - { "id", "id", &u.ID }, - { "created", "created", &u.Created }, - { "updated", "updated", &u.Updated }, - { "username", "username", &u.Username }, - { "email", "email", &u.Email }, - { "url", "url", &u.URL }, - { "location", "location", &u.Location }, - { "bio", "bio", &u.Bio }, + {"id", "id", &u.ID}, + {"created", "created", &u.Created}, + {"updated", "updated", &u.Updated}, + {"username", "username", &u.Username}, + {"email", "email", &u.Email}, + {"url", "url", &u.URL}, + {"location", "location", &u.Location}, + {"bio", "bio", &u.Bio}, // Always fetch: - { "id", "", &u.ID }, - { "username", "", &u.Username }, + {"id", "", &u.ID}, + {"username", "", &u.Username}, }, } return u.fields diff --git a/api/graph/resolver.go b/api/graph/resolver.go index b723543..bcde705 100644 --- a/api/graph/resolver.go +++ b/api/graph/resolver.go @@ -6,7 +6,7 @@ import ( //go:generate go run github.com/99designs/gqlgen -type Resolver struct {} +type Resolver struct{} var ( repoNameRE = regexp.MustCompile(`^[A-Za-z0-9._-]+$`) diff --git a/api/loaders/middleware.go b/api/loaders/middleware.go index 2186c7d..d551513 100644 --- a/api/loaders/middleware.go +++ b/api/loaders/middleware.go @@ -40,8 +40,8 @@ func fetchUsersByID(ctx context.Context) func(ids []int) ([]*model.User, []error users := make([]*model.User, len(ids)) if err := database.WithTx(ctx, &sql.TxOptions{ Isolation: 0, - ReadOnly: true, - }, func (tx *sql.Tx) error { + ReadOnly: true, + }, func(tx *sql.Tx) error { var ( err error rows *sql.Rows @@ -83,8 +83,8 @@ func fetchUsersByName(ctx context.Context) func(names []string) ([]*model.User, users := make([]*model.User, len(names)) if err := database.WithTx(ctx, &sql.TxOptions{ Isolation: 0, - ReadOnly: true, - }, func (tx *sql.Tx) error { + ReadOnly: true, + }, func(tx *sql.Tx) error { var ( err error rows *sql.Rows @@ -126,8 +126,8 @@ func fetchRepositoriesByID(ctx context.Context) func(ids []int) ([]*model.Reposi repos := make([]*model.Repository, len(ids)) if err := database.WithTx(ctx, &sql.TxOptions{ Isolation: 0, - ReadOnly: true, - }, func (tx *sql.Tx) error { + ReadOnly: true, + }, func(tx *sql.Tx) error { var ( err error rows *sql.Rows @@ -178,8 +178,8 @@ func fetchRepositoriesByName(ctx context.Context) func(names []string) ([]*model repos := make([]*model.Repository, len(names)) if err := database.WithTx(ctx, &sql.TxOptions{ Isolation: 0, - ReadOnly: true, - }, func (tx *sql.Tx) error { + ReadOnly: true, + }, func(tx *sql.Tx) error { var ( err error rows *sql.Rows @@ -225,8 +225,8 @@ func fetchRepositoriesByOwnerRepoName(ctx context.Context) func(names [][2]strin repos := make([]*model.Repository, len(names)) if err := database.WithTx(ctx, &sql.TxOptions{ Isolation: 0, - ReadOnly: true, - }, func (tx *sql.Tx) error { + ReadOnly: true, + }, func(tx *sql.Tx) error { var ( err error rows *sql.Rows diff --git a/api/webhooks/webhooks.go b/api/webhooks/webhooks.go index b5d049b..c2f7e55 100644 --- a/api/webhooks/webhooks.go +++ b/api/webhooks/webhooks.go @@ -45,9 +45,9 @@ type RepoWebhookPayload struct { Visibility string `json:"visibility"` Owner struct { - CanonicalName string `json:"canonical_name"` - Name string `json:"name"` - }`json:"owner"` + CanonicalName string `json:"canonical_name"` + Name string `json:"name"` + } `json:"owner"` } func DeliverLegacyRepoCreate(ctx context.Context, repo *model.Repository) { -- 2.38.4