Skip to content

Database

emli edited this page Nov 20, 2017 · 31 revisions

db

Gorjun uses bolt. Bolt an embedded key/value database for Go. Bucket is table in bolt.

Gorjun database directory is /opt/gorjun/data/db/my.db. If it not exist it will created automatically. Before create directory opt/gorjun.

  • MyBucket - store information about all files in Gorjun. Here key - is a file UUID.
  • Users - store all users registered in the system. Key is a username, the value is a bucket with multiple GPG-keys.
  • SearchIndex - store a search index for fast accessing artifacts. Key - filename, value - bucket with files UUIDs.
  • Tokens - store authentication tokens for user sessions. Key - token, value bucket with username and date of creation.
  • AuthID - store AuthID(random string) that user should sign to get token. Key - authID, value - username.
  • Tags - another search index that is used to group templates by tags. Key - tag, value - template UUIDs

Working with Tokens

  1. How to get tokens?

b := tx.Bucket(tokens).Bucket([]byte(token))

As you see above tokens is bucket that store token as key, value bucket with username and date of creation. Token is key.

  1. How to put values?

b.Put([]byte("name"), []byte(name))

b.Put([]byte("date"), now)

  1. How to get date and username for token? After assign bucket to b, we can get value by keys.

b.Get([]byte("date"))

b.Get([]byte("name"))