mirror of
https://github.com/owenthereal/jqplay.git
synced 2025-04-19 06:02:17 +03:00
Remove snippet salt (too complex)
This commit is contained in:
parent
1e495af42b
commit
86e3a18d27
@ -1,2 +1 @@
|
||||
DATABASE_URL="dbname=jqplay sslmode=disable"
|
||||
SNIPPET_SALT=1234
|
||||
|
@ -10,7 +10,6 @@ type Config struct {
|
||||
Port string `env:"PORT,default=3000"`
|
||||
GinMode string `env:"GIN_MODE,default=debug"`
|
||||
DatabaseURL string `env:"DATABASE_URL,required"`
|
||||
SnippetSalt string `env:"SNIPPET_SALT,required"`
|
||||
AssetHost string `env:"ASSET_HOST"`
|
||||
JQVer string
|
||||
}
|
||||
|
10
server/db.go
10
server/db.go
@ -48,22 +48,21 @@ func ToJQ(s *Snippet) *jq.JQ {
|
||||
}
|
||||
}
|
||||
|
||||
func ConnectDB(url, salt string) (*DB, error) {
|
||||
func ConnectDB(url string) (*DB, error) {
|
||||
db, err := sqlx.Connect("postgres", url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DB{DB: db, salt: salt}, nil
|
||||
return &DB{db}, nil
|
||||
}
|
||||
|
||||
type DB struct {
|
||||
*sqlx.DB
|
||||
salt string
|
||||
}
|
||||
|
||||
func (db *DB) UpsertSnippet(s *Snippet) (string, error) {
|
||||
slug := db.slug(s)
|
||||
slug := slug(s)
|
||||
_, err := db.NamedExec(upsertSnippetQuery,
|
||||
map[string]interface{}{
|
||||
"slug": slug,
|
||||
@ -82,9 +81,8 @@ func (db *DB) GetSnippet(id string) (*Snippet, error) {
|
||||
return &s, err
|
||||
}
|
||||
|
||||
func (db *DB) slug(s *Snippet) string {
|
||||
func slug(s *Snippet) string {
|
||||
h := sha1.New()
|
||||
io.WriteString(h, db.salt)
|
||||
io.WriteString(h, s.J)
|
||||
io.WriteString(h, s.Q)
|
||||
io.WriteString(h, s.O)
|
||||
|
@ -20,7 +20,7 @@ type Server struct {
|
||||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
db, err := ConnectDB(s.Config.DatabaseURL, s.Config.SnippetSalt)
|
||||
db, err := ConnectDB(s.Config.DatabaseURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user