Skip to content

Commit 110315e

Browse files
committed
Move initialization to new function
1 parent 5e545f1 commit 110315e

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ type BlogDetails struct {
2525
Website string `json:"website"`
2626
}
2727

28-
func init() {
28+
func initialize(db *bolt.DB) {
2929
// Handles db/bucket creation
30-
db, err := bolt.Open("goblog.db", 0600, nil)
31-
if err != nil {
32-
fmt.Println(err)
33-
}
34-
defer db.Close()
3530

3631
db.Update(func(tx *bolt.Tx) error {
3732
_, err := tx.CreateBucketIfNotExists([]byte("UsersBucket")) // email -> password
@@ -412,6 +407,7 @@ func main() {
412407
fmt.Println(err)
413408
}
414409
defer db.Close()
410+
initialize(db)
415411
fmt.Println("Started server on port 1337")
416412
router := mux.NewRouter()
417413
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)