-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.service.go
50 lines (43 loc) · 1.62 KB
/
common.service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package services
import (
"errors"
"math/rand"
"strconv"
"strings"
"time"
"github.com/cognitive-neuroscience/neuron/src/database"
"github.com/cognitive-neuroscience/neuron/src/email"
axonlogger "github.com/cognitive-neuroscience/neuron/src/logger"
)
var userRepositoryImpl = database.UserRepository{}
var taskRespositoryImpl = database.TaskRepository{}
var studyRepositoryImpl = database.StudyRepository{}
var participantDataRepositoryImpl = database.ParticipantDataRepository{}
var organizationRepositoryImpl = database.OrganizationRepository{}
var studyUserRepositoryImpl = database.StudyUserRepository{}
var emailServiceImpl = email.EmailBaseService{}
var authServiceImpl = AuthService{}
var userServiceImpl = UserService{}
var crowdSourcedUserRepositoryImpl = database.CrowdSourcedUserRepository{}
func convertStringToUint8(str string) (uint, error) {
parsedUint64, err := strconv.ParseUint(str, 10, 64)
if err != nil {
axonlogger.WarningLogger.Println("error parsing id to uint", err)
return 0, errors.New("could not parse the given string")
}
parsedUint := uint(parsedUint64)
return parsedUint, nil
}
// CodeCharacters represents the atomic characters that make up a short code
// it omits vowels to ensure no profanity is accidentally generated
var codeCharacters string = "bcdfghjklmnpqrstvwxyz0123456789"
// generateCode creates a code using the CharacterCode string of x size
func generateCode(size int) string {
rand.Seed(time.Now().UnixNano())
var str strings.Builder
for i := 0; i < size; i++ {
randIndex := rand.Intn(len(codeCharacters))
str.WriteString(string(codeCharacters[randIndex]))
}
return str.String()
}