src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

store.go (443B)


      1 package store
      2 
      3 import (
      4 	"fmt"
      5 	"os"
      6 )
      7 
      8 const permissions = 0700
      9 
     10 type Store struct {
     11 	Dir string
     12 }
     13 
     14 func Open(dir string) (*Store, error) {
     15 	var store = &Store{Dir: dir}
     16 
     17 	// Create the directory, if it doesn't exist.
     18 	if _, err := os.Stat(dir); os.IsNotExist(err) {
     19 		if err := os.MkdirAll(dir, os.ModeDir|permissions); err != nil {
     20 			return nil, fmt.Errorf(
     21 				"failed to create dqs directory: %w", err,
     22 			)
     23 		}
     24 	}
     25 
     26 	return store, nil
     27 }