-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted to gorm for DB & organized code (#540)
- Loading branch information
Showing
201 changed files
with
11,209 additions
and
1,531 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package helpers | ||
|
||
import ( | ||
"github.com/mynaparrot/plugnmeet-server/pkg/config" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func HandleCloseConnections() { | ||
if config.GetConfig() == nil { | ||
return | ||
} | ||
|
||
// handle to close DB connection | ||
db, err := config.GetConfig().ORM.DB() | ||
if err == nil { | ||
_ = db.Close() | ||
} | ||
|
||
// close redis | ||
_ = config.GetConfig().RDS.Close() | ||
|
||
// close logger | ||
logrus.Exit(0) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package helpers | ||
|
||
import ( | ||
"github.com/mynaparrot/plugnmeet-protocol/factory" | ||
"github.com/mynaparrot/plugnmeet-server/pkg/config" | ||
"github.com/mynaparrot/plugnmeet-server/pkg/temporary" | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
) | ||
|
||
func ReadYamlConfigFile(file string) (*config.AppConfig, error) { | ||
yamlFile, err := os.ReadFile(file) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
appCnf := new(config.AppConfig) | ||
err = yaml.Unmarshal(yamlFile, &appCnf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// get current working dir | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// set the root path | ||
appCnf.RootWorkingDir = wd | ||
|
||
return appCnf, err | ||
} | ||
|
||
func PrepareServer(appCnf *config.AppConfig) error { | ||
// orm | ||
err := temporary.NewDatabaseConnection(appCnf) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// set redis connection | ||
rds, err := factory.NewRedisConnection(appCnf.RedisInfo) | ||
if err != nil { | ||
return err | ||
} | ||
appCnf.RDS = rds | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.