mirror of
https://github.com/getAlby/lndhub.go.git
synced 2025-12-23 15:44:51 +01:00
move config to lib
This commit is contained in:
@@ -18,11 +18,11 @@ type AuthController struct {
|
|||||||
svc *lib.LndhubService
|
svc *lib.LndhubService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuthController(svc *lib.LndhubService, secret []byte, expiry int) *AuthController {
|
func NewAuthController(svc *lib.LndhubService) *AuthController {
|
||||||
return &AuthController{
|
return &AuthController{
|
||||||
svc: svc,
|
svc: svc,
|
||||||
JWTSecret: secret,
|
JWTSecret: svc.Config.JWTSecret,
|
||||||
JWTExpiry: expiry,
|
JWTExpiry: svc.Config.JWTExpiry,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type LndhubService struct {
|
type LndhubService struct {
|
||||||
|
Config *Config
|
||||||
DB *bun.DB
|
DB *bun.DB
|
||||||
LndClient *lnrpc.LightningClient
|
LndClient *lnrpc.LightningClient
|
||||||
}
|
}
|
||||||
|
type Config struct {
|
||||||
|
DatabaseUri string `envconfig:"DATABASE_URI" required:"true"`
|
||||||
|
SentryDSN string `envconfig:"SENTRY_DSN"`
|
||||||
|
LogFilePath string `envconfig:"LOG_FILE_PATH"`
|
||||||
|
JWTSecret []byte `envconfig:"JWT_SECRET" required:"true"`
|
||||||
|
JWTExpiry int `envconfig:"JWT_EXPIRY" default:"604800"` // in seconds
|
||||||
|
LNDAddress string `envconfig:"LND_ADDRESS" required:"true"`
|
||||||
|
LNDMacaroonHex string `envconfig:"LND_MACAROON_HEX" required:"true"`
|
||||||
|
LNDCertHex string `envconfig:"LND_CERT_HEX"`
|
||||||
|
}
|
||||||
|
|
||||||
func (svc *LndhubService) CurrentBalance(ctx context.Context, userId int64) (int64, error) {
|
func (svc *LndhubService) CurrentBalance(ctx context.Context, userId int64) (int64, error) {
|
||||||
var balance int64
|
var balance int64
|
||||||
|
|||||||
18
main.go
18
main.go
@@ -26,26 +26,15 @@ import (
|
|||||||
"github.com/ziflex/lecho/v3"
|
"github.com/ziflex/lecho/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
DatabaseUri string `envconfig:"DATABASE_URI" required:"true"`
|
|
||||||
SentryDSN string `envconfig:"SENTRY_DSN"`
|
|
||||||
LogFilePath string `envconfig:"LOG_FILE_PATH"`
|
|
||||||
JWTSecret []byte `envconfig:"JWT_SECRET" required:"true"`
|
|
||||||
JWTExpiry int `envconfig:"JWT_EXPIRY" default:"604800"` // in seconds
|
|
||||||
LNDAddress string `envconfig:"LND_ADDRESS" required:"true"`
|
|
||||||
LNDMacaroonHex string `envconfig:"LND_MACAROON_HEX" required:"true"`
|
|
||||||
LNDCertHex string `envconfig:"LND_CERT_HEX"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var c Config
|
c := &lib.Config{}
|
||||||
|
|
||||||
// Load configruation from environment variables
|
// Load configruation from environment variables
|
||||||
err := godotenv.Load(".env")
|
err := godotenv.Load(".env")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Failed to load .env file")
|
fmt.Println("Failed to load .env file")
|
||||||
}
|
}
|
||||||
err = envconfig.Process("", &c)
|
err = envconfig.Process("", c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@@ -113,11 +102,12 @@ func main() {
|
|||||||
logger.Infof("Connected to LND: %s - %s", getInfo.Alias, getInfo.IdentityPubkey)
|
logger.Infof("Connected to LND: %s - %s", getInfo.Alias, getInfo.IdentityPubkey)
|
||||||
|
|
||||||
svc := &lib.LndhubService{
|
svc := &lib.LndhubService{
|
||||||
|
Config: c,
|
||||||
DB: dbConn,
|
DB: dbConn,
|
||||||
LndClient: &lndClient,
|
LndClient: &lndClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
e.POST("/auth", controllers.NewAuthController(svc, c.JWTSecret, c.JWTExpiry).Auth)
|
e.POST("/auth", controllers.NewAuthController(svc).Auth)
|
||||||
e.POST("/create", controllers.NewCreateUserController(svc).CreateUser)
|
e.POST("/create", controllers.NewCreateUserController(svc).CreateUser)
|
||||||
|
|
||||||
secured := e.Group("", tokens.Middleware(c.JWTSecret))
|
secured := e.Group("", tokens.Middleware(c.JWTSecret))
|
||||||
|
|||||||
Reference in New Issue
Block a user