本文整理匯總了Golang中github.com/crunchydata/crunchy-postgresql-manager/util.GetConnection函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetConnection函數的具體用法?Golang GetConnection怎麽用?Golang GetConnection使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetConnection函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Login
// Login perform a login using passed credentials and return a token if successful
func Login(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
ID := r.PathParam("ID")
PSW := r.PathParam("PSW")
if ID == "" || PSW == "" {
logit.Error.Println("Login: ID or PSW not supplied")
rest.Error(w, "ID or PSW not supplied", http.StatusBadRequest)
}
//logit.Info.Println("Login: called")
tokenContents, err := secimpl.Login(dbConn, ID, PSW)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
//w.WriteHeader(http.StatusOK)
token := LoginToken{tokenContents}
logit.Info.Println("sending back token " + token.Contents)
w.WriteJson(&token)
}
示例2: DeleteRole
// DeleteRole delete a CPM role
func DeleteRole(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-user")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
if r.PathParam("ID") == "" {
logit.Error.Println("DeleteRole: error ID required")
rest.Error(w, "ID required", http.StatusBadRequest)
return
}
err = secimpl.DeleteRole(dbConn, r.PathParam("ID"))
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例3: GetAllUsers
// GetAllUsers return all CPM users
func GetAllUsers(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
usersList, err := secimpl.GetAllUsers(dbConn)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
//for i := range usersList {
//logit.Info.Println("GetAllUsers: secimpl.GetAllUsers userName=" + usersList[i].Name)
//}
w.WriteHeader(http.StatusOK)
w.WriteJson(&usersList)
}
示例4: GetAllSettings
// GetAllSettings return all settings
func GetAllSettings(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
results, err := admindb.GetAllSettings(dbConn)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
}
settings := make([]types.Setting, len(results))
i := 0
for i = range results {
settings[i].Name = results[i].Name
settings[i].Value = results[i].Value
settings[i].Description = results[i].Description
settings[i].UpdateDate = results[i].UpdateDate
i++
}
w.WriteJson(&settings)
}
示例5: GetRole
// GetRole return a role
func GetRole(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
Name := r.PathParam("Name")
if Name == "" {
logit.Error.Println("GetRole: error Name required")
rest.Error(w, "Name required", http.StatusBadRequest)
return
}
var role sec.Role
role, err = secimpl.GetRole(dbConn, Name)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
w.WriteJson(&role)
}
示例6: RulesGetAll
// RulesGetAll returns all the access rule definitions
func RulesGetAll(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
rules, err := GetAllRules(dbConn)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.WriteHeader(http.StatusOK)
w.WriteJson(&rules)
}
示例7: GetHealthCheck
// GetHealthCheck returns the latest health check metrics that have been collected
func GetHealthCheck(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection("clusteradmin")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
var results []types.HealthCheck
results, err = admindb.GetHealthCheck(dbConn)
if err != nil {
logit.Error.Println(err.Error())
w.WriteJson(&results)
return
}
w.WriteJson(&results)
}
示例8: Logout
// Logout perform a logout based on a given token
func Logout(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
token := r.PathParam("Token")
if token == "" {
logit.Error.Println("Logout: Token not supplied")
rest.Error(w, "Token not supplied", http.StatusBadRequest)
}
err = secimpl.Logout(dbConn, token)
if err != nil {
logit.Error.Println("Logout: error secimpl call" + err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteJson(&status)
}
示例9: StartCluster
// StartCluster starts all nodes in a cluster
func StartCluster(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-cluster")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
logit.Error.Println("StartCluster: error cluster ID required")
rest.Error(w, "cluster ID required", http.StatusBadRequest)
return
}
cluster, err := admindb.GetCluster(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
}
//start docker containers
containers, err := admindb.GetAllContainersForCluster(dbConn, cluster.ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
}
i := 0
i = 0
var response swarmapi.DockerStartResponse
for i = range containers {
req := &swarmapi.DockerStartRequest{}
req.ContainerName = containers[i].Name
logit.Info.Println("will attempt to start container " + req.ContainerName)
response, err = swarmapi.DockerStart(req)
if err != nil {
logit.Error.Println("StartCluster: error when trying to start container" + err.Error())
}
logit.Info.Println("StartCluster: started " + response.Output)
i++
}
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteHeader(http.StatusOK)
w.WriteJson(&status)
}
示例10: StatusUpdate
// StatusUpdate called by backup jobs as they execute
func StatusUpdate(w rest.ResponseWriter, r *rest.Request) {
request := TaskStatus{}
err := r.DecodeJsonPayload(&request)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var dbConn *sql.DB
dbConn, err = util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer dbConn.Close()
//logit.Info.Println("StatusUpdate called")
err = UpdateStatus(dbConn, &request)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
response := StatusUpdateResponse{}
response.Output = "ok"
w.WriteJson(&response)
}
示例11: ContainerAccessRuleGetAll
// ContainerAccessRuleGetAll returns all the rules selected for a container
func ContainerAccessRuleGetAll(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println("BackupNow: error " + err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println("ContainerRulesGetAll: authorize error " + err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ContainerID := r.PathParam("ID")
if ContainerID == "" {
rest.Error(w, "ID required", http.StatusBadRequest)
return
}
cars, err := GetAllContainerAccessRule(dbConn, ContainerID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.WriteHeader(http.StatusOK)
w.WriteJson(&cars)
}
示例12: GetCluster
// GetCluster returns a given cluster definition
func GetCluster(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
results, err := admindb.GetCluster(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
}
cluster := types.Cluster{}
cluster.ID = results.ID
cluster.ProjectID = results.ProjectID
cluster.Name = results.Name
cluster.ClusterType = results.ClusterType
cluster.Status = results.Status
cluster.CreateDate = results.CreateDate
cluster.Containers = results.Containers
//logit.Info.Println("GetCluser:db call results=" + results.ID)
w.WriteJson(&cluster)
}
示例13: RulesDelete
// RulesDelete deletes a given rule
func RulesDelete(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
rest.Error(w, "ID required", http.StatusBadRequest)
return
}
err = DeleteRule(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
status := types.SimpleStatus{}
status.Status = "OK"
w.WriteHeader(http.StatusOK)
w.WriteJson(&status)
}
示例14: PostCluster
// PostCluster updates or inserts a new cluster definition
func PostCluster(w rest.ResponseWriter, r *rest.Request) {
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
//logit.Info.Println("PostCluster: in PostCluster")
cluster := types.Cluster{}
err = r.DecodeJsonPayload(&cluster)
if err != nil {
logit.Error.Println("error in decode" + err.Error())
rest.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = secimpl.Authorize(dbConn, cluster.Token, "perm-cluster")
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
if cluster.Name == "" {
logit.Error.Println("PostCluster: error in Name")
rest.Error(w, "cluster name required", http.StatusBadRequest)
return
}
//logit.Info.Println("PostCluster: have ID=" + cluster.ID + " Name=" + cluster.Name + " type=" + cluster.ClusterType + " status=" + cluster.Status)
dbcluster := types.Cluster{}
dbcluster.ID = cluster.ID
dbcluster.ProjectID = cluster.ProjectID
dbcluster.Name = cluster.Name
dbcluster.ClusterType = cluster.ClusterType
dbcluster.Status = cluster.Status
dbcluster.Containers = cluster.Containers
if cluster.ID == "" {
strid, err := admindb.InsertCluster(dbConn, dbcluster)
newid := strconv.Itoa(strid)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
cluster.ID = newid
} else {
//logit.Info.Println("PostCluster: about to call UpdateCluster")
err2 := admindb.UpdateCluster(dbConn, dbcluster)
if err2 != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
w.WriteJson(&cluster)
}
示例15: GetStatus
// GetStatus returns the status of a given task schedule
func GetStatus(w rest.ResponseWriter, r *rest.Request) {
Token := r.PathParam("Token")
if Token == "" {
rest.Error(w, "Token required", 400)
return
}
dbConn, err := util.GetConnection(CLUSTERADMIN_DB)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
defer dbConn.Close()
err = secimpl.Authorize(dbConn, Token, "perm-read")
if err != nil {
logit.Error.Println("validate token error " + err.Error())
rest.Error(w, err.Error(), http.StatusUnauthorized)
return
}
ID := r.PathParam("ID")
if ID == "" {
rest.Error(w, "ID required", 400)
return
}
stat, err := task.GetStatus(dbConn, ID)
if err != nil {
logit.Error.Println(err.Error())
rest.Error(w, err.Error(), 400)
return
}
w.WriteHeader(http.StatusOK)
w.WriteJson(stat)
}