Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kcrong committed Oct 3, 2023
1 parent adf73ae commit 609507d
Show file tree
Hide file tree
Showing 36 changed files with 7,408 additions and 3 deletions.
6 changes: 6 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hodlgap/captive-portal/pkg"
"github.com/hodlgap/captive-portal/pkg/config"
"github.com/hodlgap/captive-portal/pkg/handler"
"github.com/hodlgap/captive-portal/pkg/models"
)

const (
Expand Down Expand Up @@ -46,6 +47,11 @@ func main() {
redisCli := redis.NewClient(redisOpt)
redisCli.AddHook(nrredis.NewHook(redisOpt))

db := models.MustGetDB(c.DB.Host, c.DB.User, c.DB.Password, c.DB.Name, c.DB.Port)
if err := db.Ping(); err != nil {
log.Fatalf("%+v", errors.WithStack(err))
}

app = handler.SetRoute(c, app, redisCli)

// Start server
Expand Down
3 changes: 2 additions & 1 deletion config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ redis:
db:
host: 127.0.0.1
port: 5432
name: "captive_portal"
user: "postgres"
name: "captive-portal"
password: "example"
6 changes: 5 additions & 1 deletion db/templates/singleton/psql.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import (
"fmt"

log "github.com/sirupsen/logrus"

_ "github.com/lib/pq"
)

const (
Expand All @@ -11,7 +13,9 @@ const (
)

func MustGetDB(host, user, pass, dbName string, port int) *sql.DB {
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=true", user, pass, host, port, dbName))
db, err := sql.Open("postgres", fmt.Sprintf(
"user=%s password=%s host=%s port=%d dbname=%s sslmode=disable", user, pass, host, port, dbName,
))
if err != nil {
panic(err)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/go-redis/redismock/v9 v9.0.3
github.com/labstack/echo/v4 v4.11.1
github.com/labstack/gommon v0.4.0
github.com/lib/pq v1.10.6
github.com/newrelic/go-agent/v3 v3.26.0
github.com/newrelic/go-agent/v3/integrations/nrecho-v4 v1.0.4
github.com/newrelic/go-agent/v3/integrations/nrredis-v9 v1.0.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ github.com/labstack/echo/v4 v4.11.1/go.mod h1:YuYRTSM3CHs2ybfrL8Px48bO6BAnYIN4l8
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.6 h1:jbk+ZieJ0D7EVGJYpL9QTz7/YW6UHbmdnZWYyK5cdBs=
github.com/lib/pq v1.10.6/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
Expand Down
1 change: 1 addition & 0 deletions pkg/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Config struct {
Newrelic `yaml:"newrelic"`
Openwrt `yaml:"openwrt"`
Redis `yaml:"redis"`
DB `yaml:"db"`
}

// Parse yaml to go struct
Expand Down
6 changes: 5 additions & 1 deletion pkg/models/psql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions vendor/github.com/lib/pq/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendor/github.com/lib/pq/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions vendor/github.com/lib/pq/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions vendor/github.com/lib/pq/TESTS.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 609507d

Please sign in to comment.