<commit_before>package models

import (
  "fmt"
  "github.com/gokyle/uuid"
  "github.com/spacedock-io/registry/db"
  "strings"
)

type Token struct {
  Id        int64
  Signature string
  Access    string
  UserId    int64
  RepoId    int64
  Repo      string
}

func CreateToken(access string, uid int64, repo string) (Token, bool) {
  token := Token{}
  // @TODO: Validate access string
  token.Access = access
  sig, err := uuid.GenerateV4String()
  if err != nil {
    return Token{}, false
  }
  token.Signature = sig
  token.UserId = uid
  token.Repo = repo
  return token, true
}

func GetToken(user *User, repo, access string) (Token, error) {
  t := Token{
    UserId: user.Id,
    Access: access,
    Repo: repo,
  }

  q := db.DB.Where(&t).Find(&t)
  if q.RecordNotFound() {
    return Token{}, TokenNotFound
  } else if q.Error != nil {
    return Token{}, q.Error
  }

  return Token{}, nil
}

func GetTokenString(token string) (Token, error) {
  t := Token{}

  split := strings.Split(token, ",")
  for _, v := range split {
    v := strings.Split(v, "=")
    switch v[0] {
      case "signature": t.Signature = v[1]
      case "repository": t.Repo = v[1]
      case "access": t.Access = v[1]
    }
  }

  q := db.DB.Where(&t).Find(&t)
  if q.RecordNotFound() {
    return Token{}, TokenNotFound
  } else if q.Error != nil {
    return Token{}, q.Error
  }
  return t, nil
}
<commit_msg>Would help if I returned the token. -_-<commit_after>package models

import (
  "fmt"
  "github.com/gokyle/uuid"
  "github.com/spacedock-io/registry/db"
  "strings"
)

type Token struct {
  Id        int64
  Signature string
  Access    string
  UserId    int64
  RepoId    int64
  Repo      string
}

func CreateToken(access string, uid int64, repo string) (Token, bool) {
  token := Token{}
  // @TODO: Validate access string
  token.Access = access
  sig, err := uuid.GenerateV4String()
  if err != nil {
    return Token{}, false
  }
  token.Signature = sig
  token.UserId = uid
  token.Repo = repo
  return token, true
}

func GetToken(user *User, repo, access string) (Token, error) {
  t := Token{
    UserId: user.Id,
    Access: access,
    Repo: repo,
  }

  q := db.DB.Where(&t).Find(&t)
  if q.RecordNotFound() {
    return Token{}, TokenNotFound
  } else if q.Error != nil {
    return Token{}, q.Error
  }

  return t, nil
}

func GetTokenString(token string) (Token, error) {
  t := Token{}

  split := strings.Split(token, ",")
  for _, v := range split {
    v := strings.Split(v, "=")
    switch v[0] {
      case "signature": t.Signature = v[1]
      case "repository": t.Repo = v[1]
      case "access": t.Access = v[1]
    }
  }

  q := db.DB.Where(&t).Find(&t)
  if q.RecordNotFound() {
    return Token{}, TokenNotFound
  } else if q.Error != nil {
    return Token{}, q.Error
  }
  return t, nil
}

{'fraction_non_alphanumeric': 0.14341359773371104, 'fraction_numerical': 0.009206798866855524, 'mean_word_length': 2.654592496765847, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '865230', 'n_tokens_mistral': 1012, 'n_tokens_neox': 1003, 'n_words': 279}