Skip to content

Commit

Permalink
Merge pull request #21 from karmanyaahm/main
Browse files Browse the repository at this point in the history
Changes for external library users
  • Loading branch information
karmanyaahm authored Dec 25, 2021
2 parents e7eac68 + 7ee8b01 commit 0c55cf0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func (s Storage) DB() *gorm.DB {
}

func (s Storage) NewConnection(appID, appToken string, settings string) *Connection {
existing := s.getFirst(Connection{AppID: appID, AppToken: appToken})
return s.NewConnectionFull(appID, appToken, uuid.New().String(), settings)
}

func (s Storage) NewConnectionFull(appID, appToken, pubToken, settings string) *Connection {
existing := s.GetFirst(Connection{AppID: appID, AppToken: appToken})
if existing != nil {
existing.Settings = settings
if err := s.db.Save(existing).Error; err != nil {
Expand All @@ -44,7 +48,7 @@ func (s Storage) NewConnection(appID, appToken string, settings string) *Connect
c := Connection{
AppID: appID,
AppToken: appToken,
PublicToken: uuid.New().String(),
PublicToken: pubToken,
Settings: settings,
}
result := s.db.Create(&c)
Expand All @@ -56,7 +60,7 @@ func (s Storage) NewConnection(appID, appToken string, settings string) *Connect

func (s Storage) DeleteConnection(token string) (*Connection, error) {
c := Connection{AppToken: token}
conn := s.getFirst(c)
conn := s.GetFirst(c)
if conn == nil {
return nil, errors.New("connection not found")
}
Expand All @@ -66,7 +70,7 @@ func (s Storage) DeleteConnection(token string) (*Connection, error) {

func (s Storage) GetConnectionbyPublic(publicToken string) *Connection {
c := Connection{PublicToken: publicToken}
return s.getFirst(c)
return s.GetFirst(c)
}

func (s Storage) GetUnequalSettings(latestSettings string) (ans []*Connection) {
Expand All @@ -78,7 +82,7 @@ func (s Storage) GetUnequalSettings(latestSettings string) (ans []*Connection) {

}

func (s Storage) getFirst(c Connection) *Connection {
func (s Storage) GetFirst(c Connection) *Connection {
result := s.db.Where(&c).First(&c)
if result.Error != nil || result.RowsAffected == 0 {
return nil
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Logger struct {
}

func (Logger) Debugln(inps ...interface{}) {
if os.Getenv("UP_NP2P_DEBUG") == "true" || strings.HasPrefix(os.Args[0], "/tmp/go-build") {
if os.Getenv("DEBUG") == "true" || strings.HasPrefix(os.Args[0], "/tmp/go-build") {
log.Println(inps...)
}
}
Expand Down

0 comments on commit 0c55cf0

Please sign in to comment.