Start using go mod

This commit is contained in:
luk3yx 2021-02-22 19:19:35 +13:00
parent 7f7436cf62
commit e9d90a12f7
17 changed files with 41 additions and 30 deletions

View File

@ -5,13 +5,7 @@ This is the core code of the current release of
## Dependencies ## Dependencies
- [Go](https://golang.org) 1.10+, Go 1.14 or later recommended. [Go](https://golang.org) 1.13+
- [bbolt](https://github.com/etcd-io/bbolt)
- `go get go.etcd.io/bbolt`
- [httprouter](https://github.com/julienschmidt/httprouter)
- `go get github.com/julienschmidt/httprouter`
- [yaml](https://gopkg.in/yaml.v2)
- `go get gopkg.in/yaml.v2`
## Configuration ## Configuration

9
go.mod Normal file
View File

@ -0,0 +1,9 @@
module github.com/luk3yx/lurkcoin-core
go 1.13
require (
github.com/julienschmidt/httprouter v1.3.0
go.etcd.io/bbolt v1.3.5
gopkg.in/yaml.v2 v2.4.0
)

9
go.sum Normal file
View File

@ -0,0 +1,9 @@
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

View File

@ -22,11 +22,11 @@ import (
"crypto/sha512" "crypto/sha512"
"encoding/hex" "encoding/hex"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"github.com/luk3yx/lurkcoin-core/lurkcoin"
"html" "html"
"html/template" "html/template"
"io" "io"
"log" "log"
"lurkcoin"
"net/http" "net/http"
"regexp" "regexp"
"strings" "strings"
@ -327,8 +327,8 @@ type adminPagesSummary struct {
} }
func parseNumbers(n1, n2 string) (lurkcoin.Currency, lurkcoin.Currency, bool) { func parseNumbers(n1, n2 string) (lurkcoin.Currency, lurkcoin.Currency, bool) {
n1 = strings.Replace(n1, ",", "", -1) n1 = strings.ReplaceAll(n1, ",", "")
n2 = strings.Replace(n2, ",", "", -1) n2 = strings.ReplaceAll(n2, ",", "")
var res1, res2 lurkcoin.Currency var res1, res2 lurkcoin.Currency
var err error var err error

View File

@ -20,11 +20,11 @@ package api
import ( import (
"fmt" "fmt"
"github.com/luk3yx/lurkcoin-core/lurkcoin"
"github.com/luk3yx/lurkcoin-core/lurkcoin/databases"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"io/ioutil" "io/ioutil"
"log" "log"
"lurkcoin"
"lurkcoin/databases"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -158,7 +158,7 @@ func StartServer(config *Config) {
// Only call chmod if no other users can write to the directory // Only call chmod if no other users can write to the directory
if stat, err := os.Stat(filepath.Dir(address)); err == nil { if stat, err := os.Stat(filepath.Dir(address)); err == nil {
changeSocketPermissions = stat.Mode() & 022 == 0 changeSocketPermissions = stat.Mode()&022 == 0
} }
} }

View File

@ -22,8 +22,8 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"github.com/luk3yx/lurkcoin-core/lurkcoin"
"io" "io"
"lurkcoin"
"net/http" "net/http"
"strings" "strings"
) )

View File

@ -22,8 +22,8 @@ package api
import ( import (
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"github.com/luk3yx/lurkcoin-core/lurkcoin"
"log" "log"
"lurkcoin"
) )
func addV2API(_ *httprouter.Router, _ lurkcoin.Database, _ string) { func addV2API(_ *httprouter.Router, _ lurkcoin.Database, _ string) {

View File

@ -28,7 +28,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"lurkcoin" "github.com/luk3yx/lurkcoin-core/lurkcoin"
"math/big" "math/big"
"net/http" "net/http"
"strconv" "strconv"
@ -253,7 +253,7 @@ func addV2API(router *httprouter.Router, db lurkcoin.Database,
return exc, nil return exc, nil
} }
s := func(n string) string { s := func(n string) string {
return strings.Replace(n, "|", "/", -1) return strings.ReplaceAll(n, "|", "/")
} }
transaction := transactions[0] transaction := transactions[0]
// To support fragile clients (such as versions of the lurkcoin // To support fragile clients (such as versions of the lurkcoin
@ -261,7 +261,7 @@ func addV2API(router *httprouter.Router, db lurkcoin.Database,
return fmt.Sprintf("%g|%d|%s|%s|%s", return fmt.Sprintf("%g|%d|%s|%s|%s",
exc, exc,
transaction.GetLegacyID(), transaction.GetLegacyID(),
s(strings.Replace(transaction.Target, "¤", "_", -1)), s(strings.ReplaceAll(transaction.Target, "¤", "_")),
transaction.ReceivedAmount.RawString(), transaction.ReceivedAmount.RawString(),
s(transaction.String()), s(transaction.String()),
), nil ), nil
@ -270,7 +270,7 @@ func addV2API(router *httprouter.Router, db lurkcoin.Database,
for i, transaction := range transactions { for i, transaction := range transactions {
res[i] = [4]interface{}{ res[i] = [4]interface{}{
transaction.GetLegacyID(), transaction.GetLegacyID(),
strings.Replace(transaction.Target, "¤", "_", -1), strings.ReplaceAll(transaction.Target, "¤", "_"),
transaction.ReceivedAmount, transaction.ReceivedAmount,
transaction.String(), transaction.String(),
} }

View File

@ -25,7 +25,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
"lurkcoin" "github.com/luk3yx/lurkcoin-core/lurkcoin"
"net/http" "net/http"
"strings" "strings"
) )

View File

@ -239,7 +239,7 @@ func CurrencyFromFloat64(num float64) Currency {
func CurrencyFromString(num string) Currency { func CurrencyFromString(num string) Currency {
var res Currency var res Currency
if res.setString(strings.Replace(num, "_", "", -1)) { if res.setString(strings.ReplaceAll(num, "_", "")) {
return res return res
} else { } else {
return Currency{i0} return Currency{i0}
@ -248,7 +248,7 @@ func CurrencyFromString(num string) Currency {
func ParseCurrency(num string) (Currency, error) { func ParseCurrency(num string) (Currency, error) {
var res Currency var res Currency
if res.setString(strings.Replace(num, "_", "", -1)) { if res.setString(strings.ReplaceAll(num, "_", "")) {
return res, nil return res, nil
} else { } else {
return Currency{i0}, errors.New("ERR_INVALIDAMOUNT") return Currency{i0}, errors.New("ERR_INVALIDAMOUNT")

View File

@ -25,7 +25,7 @@ import (
"bytes" "bytes"
"encoding/gob" "encoding/gob"
"errors" "errors"
"lurkcoin" "github.com/luk3yx/lurkcoin-core/lurkcoin"
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
) )

View File

@ -22,8 +22,8 @@ package databases
import ( import (
"encoding/json" "encoding/json"
"github.com/luk3yx/lurkcoin-core/lurkcoin"
"io/ioutil" "io/ioutil"
"lurkcoin"
"os" "os"
"path" "path"
"sync" "sync"

View File

@ -20,7 +20,7 @@ package databases
import ( import (
"fmt" "fmt"
"lurkcoin" "github.com/luk3yx/lurkcoin-core/lurkcoin"
"sort" "sort"
"strings" "strings"
"sync" "sync"

View File

@ -59,7 +59,7 @@ var invalid_uid = regexp.MustCompile(`[^a-z0-9\_]`)
func HomogeniseUsername(username string) string { func HomogeniseUsername(username string) string {
username = strings.ToLower(username) username = strings.ToLower(username)
username = strings.Replace(username, " ", "", -1) username = strings.ReplaceAll(username, " ", "")
return invalid_uid.ReplaceAllLiteralString(username, "_") return invalid_uid.ReplaceAllLiteralString(username, "_")
} }

View File

@ -20,8 +20,8 @@ package main
import ( import (
"fmt" "fmt"
"github.com/luk3yx/lurkcoin-core/lurkcoin/api"
"log" "log"
"lurkcoin/api"
"os" "os"
) )

View File

@ -20,9 +20,9 @@ package main
import ( import (
"fmt" "fmt"
"github.com/luk3yx/lurkcoin-core/lurkcoin"
"github.com/luk3yx/lurkcoin-core/lurkcoin/api"
"log" "log"
"lurkcoin"
"lurkcoin/api"
"os" "os"
) )

1
src
View File

@ -1 +0,0 @@
.