-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: add mcache #46
perf: add mcache #46
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,27 +1,30 @@ | ||||||||
package config | ||||||||
|
||||||||
import ( | ||||||||
"database/sql" | ||||||||
"fmt" | ||||||||
) | ||||||||
|
||||||||
type DatabaseConfig struct { | ||||||||
DSN string | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
already have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to add a new configuration field for the database section. For example: database:
dsn: postgres://username:password@127.0.0.1:5432/webhookx?sslmode=disable
... The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleted. (will be done on another PR) |
||||||||
Host string `yaml:"host" default:"localhost"` | ||||||||
Port uint32 `yaml:"port" default:"5432"` | ||||||||
Username string `yaml:"username" default:"webhookx"` | ||||||||
Password string `yaml:"password" default:""` | ||||||||
Database string `yaml:"database" default:"webhookx"` | ||||||||
} | ||||||||
|
||||||||
func (cfg DatabaseConfig) GetDB() (*sql.DB, error) { | ||||||||
dsn := fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=disable", | ||||||||
cfg.Username, | ||||||||
cfg.Password, | ||||||||
cfg.Host, | ||||||||
cfg.Port, | ||||||||
cfg.Database, | ||||||||
) | ||||||||
return sql.Open("postgres", dsn) | ||||||||
func (cfg DatabaseConfig) GetDSN() string { | ||||||||
dsn := cfg.DSN | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if dsn == "" { | ||||||||
dsn = fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=disable", | ||||||||
cfg.Username, | ||||||||
cfg.Password, | ||||||||
cfg.Host, | ||||||||
cfg.Port, | ||||||||
cfg.Database, | ||||||||
) | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
return dsn | ||||||||
} | ||||||||
|
||||||||
func (cfg DatabaseConfig) Validate() error { | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declare subscribe handlers somewhere else, keep app init code clean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM. Updated.