diff options
| author | jackyzha0 <[email protected]> | 2020-05-09 20:15:59 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2020-05-09 20:15:59 -0700 |
| commit | dedabf41a18820527aed9e77b75564e69c9030ce (patch) | |
| tree | 9258832576f9c1bcad6126cf76ef8f7f6a128e82 /db/db.go | |
| parent | Merge pull request #3 from jackyzha0/doc-expiry (diff) | |
| download | ctrl-v-dedabf41a18820527aed9e77b75564e69c9030ce.tar.xz ctrl-v-dedabf41a18820527aed9e77b75564e69c9030ce.zip | |
folder refactor
Diffstat (limited to 'db/db.go')
| -rw-r--r-- | db/db.go | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/db/db.go b/db/db.go deleted file mode 100644 index 053ba87..0000000 --- a/db/db.go +++ /dev/null @@ -1,68 +0,0 @@ -package db - -import ( - "fmt" - "os" - "time" - - "github.com/jackyzha0/ctrl-v/hashing" - "github.com/joho/godotenv" - log "github.com/sirupsen/logrus" -) - -func init() { - // load .env file - err := godotenv.Load() - if err != nil { - log.Fatal("Error loading .env file: %s", err.Error()) - } - - mUser := os.Getenv("MONGO_USER") - mPass := os.Getenv("MONGO_PASS") - mIP := os.Getenv("MONGO_SHARD_URL") - - initSessions(mUser, mPass, mIP) -} - -// creates a new paste with content and hash -func New(ip, content, expiry string) error { - // generate hash from ip - hash := hashing.GenerateURI(ip) - - // create new struct - new := Paste{ - Hash: hash, - Content: content, - } - - // check if expiry - if expiry != "" { - t, err := time.Parse(time.RFC3339, expiry) - - // if time format not current - if err != nil { - return err - } - - // time is in the past - if t.After(time.Now()) { - return fmt.Errorf("err: time %s is in the past", t.String()) - } - - new.Expiry = t - - } else { - // 5 year expiry - new.Expiry = time.Now().Add(time.Hour * 43800) - } - - // insert struct - log.Infof("create new paste with hash %s", hash) - insertErr := insert(new) - return insertErr -} - -// lookup -func Lookup(hash string) (Paste, error) { - return fetch(hash) -} |