Author | Jakob Wakeling <[email protected]> |
Date | 2023-08-26 02:44:52 |
Commit | 23b01c45f7e1f6d94c5261dbbebba9c35efff731 |
Parent | ceeeb5229f041cde3b96a1ff27f91b403b205e98 |
Update to Go 1.21.0
Diffstat
M | go.mod | | | 3 | +-- |
M | go.sum | | | 10 | ++++++++-- |
M | src/admin.go | | | 7 | ++++--- |
M | src/repo.go | | | 2 | +- |
M | src/repo/create.go | | | 4 | ++-- |
M | src/repo/edit.go | | | 3 | ++- |
M | src/repo/file.go | | | 4 | ++-- |
M | src/util/util.go | | | 28 | ---------------------------- |
8 files changed, 20 insertions, 41 deletions
diff --git a/go.mod b/go.mod index 9c41378..6048434 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/Jamozed/Goit -go 1.20 +go 1.21.0 require ( github.com/adrg/xdg v0.4.0 @@ -9,7 +9,6 @@ require ( github.com/gorilla/mux v1.8.0 github.com/mattn/go-sqlite3 v1.14.17 golang.org/x/crypto v0.9.0 - golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 ) require ( diff --git a/go.sum b/go.sum index b26649a..f280e0a 100644 --- a/go.sum +++ b/go.sum @@ -7,7 +7,9 @@ github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/buildkite/terminal-to-html/v3 v3.9.1 h1:8SOCKFK9ntpYvPE3yUAXHiZYdQI4xf9o9S3wOX7x12A= github.com/buildkite/terminal-to-html/v3 v3.9.1/go.mod h1:Nsx19oOIo6MZM/cEPookXi/nrQQmnSJFLZL1KS05t+A= github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= @@ -21,19 +23,23 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0= +github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= +github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f h1:Pz0DHeFij3XFhoBRGUDPzSJ+w2UcK5/0JvF8DRI58r8= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f/go.mod h1:8LHG1a3SRW71ettAD/jW13h8c6AqjVSeL11RAdgaqpo= github.com/go-git/go-git/v5 v5.7.0 h1:t9AudWVLmqzlo+4bqdf7GY+46SUuRsx59SboFxkq2aE= github.com/go-git/go-git/v5 v5.7.0/go.mod h1:coJHKEOk5kUClpsNlXrUvPrDxY3w3gjHvhcZd8Fodw8= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= @@ -79,8 +85,6 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= -golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY= -golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -115,6 +119,7 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -122,6 +127,7 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/src/admin.go b/src/admin.go index 701317b..085375c 100644 --- a/src/admin.go +++ b/src/admin.go @@ -8,6 +8,7 @@ import ( "fmt" "log" "net/http" + "slices" "strconv" "strings" @@ -87,7 +88,7 @@ func HandleAdminUserCreate(w http.ResponseWriter, r *http.Request) { if username == "" { data.Message = "Username cannot be empty" - } else if util.SliceContains(reserved, username) { + } else if slices.Contains(reserved, username) { data.Message = "Username \"" + username + "\" is reserved" } else if exists, err := UserExists(username); err != nil { log.Println("[/admin/user/create]", err.Error()) @@ -154,7 +155,7 @@ func HandleAdminUserEdit(w http.ResponseWriter, r *http.Request) { if data.Name == "" { data.Message = "Username cannot be empty" - } else if util.SliceContains(reserved, data.Name) { + } else if slices.Contains(reserved, data.Name) { data.Message = "Username \"" + data.Name + "\" is reserved" } else if exists, err := UserExists(data.Name); err != nil { log.Println("[/admin/user/edit]", err.Error()) @@ -294,7 +295,7 @@ func HandleAdminRepoEdit(w http.ResponseWriter, r *http.Request) { if data.Name == "" { data.Message = "Name cannot be empty" - } else if util.SliceContains(reserved, data.Name) { + } else if slices.Contains(reserved, data.Name) { data.Message = "Name \"" + data.Name + "\" is reserved" } else if exists, err := RepoExists(data.Name); err != nil { log.Println("[/admin/repo/edit]", err.Error()) diff --git a/src/repo.go b/src/repo.go index e523dd7..6b2b8dc 100644 --- a/src/repo.go +++ b/src/repo.go @@ -62,7 +62,7 @@ func CreateRepo(repo Repo) error { if _, err := tx.Exec( `INSERT INTO repos (owner_id, name, name_lower, description, is_private) - VALUES (?, ?, ?, ?, ?, ?)`, + VALUES (?, ?, ?, ?, ?)`, repo.OwnerId, repo.Name, strings.ToLower(repo.Name), repo.Description, repo.IsPrivate, ); err != nil { tx.Rollback() diff --git a/src/repo/create.go b/src/repo/create.go index f0c158a..c0b9444 100644 --- a/src/repo/create.go +++ b/src/repo/create.go @@ -3,9 +3,9 @@ package repo import ( "log" "net/http" + "slices" goit "github.com/Jamozed/Goit/src" - "github.com/Jamozed/Goit/src/util" ) var reserved []string = []string{"admin", "repo", "static", "user"} @@ -30,7 +30,7 @@ func HandleCreate(w http.ResponseWriter, r *http.Request) { if data.Name == "" { data.Message = "Name cannot be empty" - } else if util.SliceContains(reserved, data.Name) { + } else if slices.Contains(reserved, data.Name) { data.Message = "Name \"" + data.Name + "\" is reserved" } else if exists, err := goit.RepoExists(data.Name); err != nil { log.Println("[/repo/create]", err.Error()) diff --git a/src/repo/edit.go b/src/repo/edit.go index 2af4bce..3ced0b8 100644 --- a/src/repo/edit.go +++ b/src/repo/edit.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "net/http" + "slices" goit "github.com/Jamozed/Goit/src" "github.com/Jamozed/Goit/src/util" @@ -64,7 +65,7 @@ func HandleEdit(w http.ResponseWriter, r *http.Request) { if data.Name == "" { data.Message = "Name cannot be empty" - } else if util.SliceContains(reserved, data.Name) { + } else if slices.Contains(reserved, data.Name) { data.Message = "Name \"" + data.Name + "\" is reserved" } else if exists, err := goit.RepoExists(data.Name); err != nil { log.Println("[/repo/edit]", err.Error()) diff --git a/src/repo/file.go b/src/repo/file.go index 21eeecf..54f0457 100644 --- a/src/repo/file.go +++ b/src/repo/file.go @@ -97,7 +97,7 @@ func HandleFile(w http.ResponseWriter, r *http.Request) { goit.HttpError(w, http.StatusInternalServerError) return } else { - buf := make([]byte, util.Min(file.Size, 512)) + buf := make([]byte, min(file.Size, 512)) if _, err := rc.Read(buf); err != nil { log.Println("[/repo/file]", err.Error()) @@ -106,7 +106,7 @@ func HandleFile(w http.ResponseWriter, r *http.Request) { } if strings.HasPrefix(http.DetectContentType(buf), "text") { - buf2 := make([]byte, util.Min(file.Size-int64(len(buf)), (10*1024*1024)-int64(len(buf)))) + buf2 := make([]byte, min(file.Size-int64(len(buf)), (10*1024*1024)-int64(len(buf)))) if _, err := rc.Read(buf2); err != nil && !errors.Is(err, io.EOF) { log.Println("[/repo/file]", err.Error()) goit.HttpError(w, http.StatusInternalServerError) diff --git a/src/util/util.go b/src/util/util.go index aa48e40..267ea22 100644 --- a/src/util/util.go +++ b/src/util/util.go @@ -10,8 +10,6 @@ import ( "net/http" "os" "path/filepath" - - "golang.org/x/exp/constraints" ) const ModeNotRegular = os.ModeSymlink | os.ModeDevice | os.ModeNamedPipe | os.ModeSocket | os.ModeCharDevice | @@ -25,32 +23,6 @@ func If[T any](cond bool, a, b T) T { } } -func SliceContains[T comparable](s []T, e T) bool { - for _, v := range s { - if v == e { - return true - } - } - - return false -} - -func Min[T constraints.Ordered](a, b T) T { - if a < b { - return a - } - - return b -} - -func Max[T constraints.Ordered](a, b T) T { - if a > b { - return a - } - - return b -} - /* Return the named cookie or nil if not found or invalid. */ func Cookie(r *http.Request, name string) *http.Cookie { c, err := r.Cookie(name)