本文整理汇总了Golang中github.com/wayneeseguin/rdpg-agent/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: httpAuth
func httpAuth(h http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, request *http.Request) {
if len(request.Header["Authorization"]) == 0 {
log.Trace(fmt.Sprintf("httpAuth(): Authorization Required"))
http.Error(w, "Authorization Required", http.StatusUnauthorized)
return
}
auth := strings.SplitN(request.Header["Authorization"][0], " ", 2)
if len(auth) != 2 || auth[0] != "Basic" {
log.Error(fmt.Sprintf("httpAuth(): Unhandled Authorization Type, Expected Basic"))
http.Error(w, "Unhandled Authroization Type, Expected Basic\n", http.StatusBadRequest)
return
}
payload, err := base64.StdEncoding.DecodeString(auth[1])
if err != nil {
log.Error(fmt.Sprintf("httpAuth(): Authorization Failed"))
http.Error(w, "Authorization Failed\n", http.StatusUnauthorized)
return
}
nv := strings.SplitN(string(payload), ":", 2)
if (len(nv) != 2) || !isAuthorized(nv[0], nv[1]) {
log.Error(fmt.Sprintf("httpAuth(): Authorization Failed"))
http.Error(w, "Authorization Failed\n", http.StatusUnauthorized)
return
}
h(w, request)
}
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:29,代码来源:api.go
示例2: OpenDB
// TODO: Instead pass back *sql.DB
func (r *RDPG) OpenDB(dbname string) error {
if r.DB == nil {
u, err := url.Parse(r.URI)
if err != nil {
log.Error(fmt.Sprintf("Failed parsing URI %s err: %s", r.URI, err))
}
u.Path = dbname
r.URI = u.String()
db, err := sqlx.Connect("postgres", r.URI)
if err != nil {
log.Error(fmt.Sprintf("Failed connecting to %s err: %s", rdpgURI, err))
return err
}
r.DB = db
} else {
err := r.DB.Ping()
if err != nil {
db, err := sqlx.Connect("postgres", r.URI)
if err != nil {
log.Error(fmt.Sprintf("Failed connecting to %s err: %s", rdpgURI, err))
proc, _ := os.FindProcess(os.Getpid())
proc.Signal(syscall.SIGTERM)
return err
}
r.DB = db
}
}
return nil
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:30,代码来源:rdpg.go
示例3: Fetch
func (c *Catalog) Fetch() (err error) {
r := rdpg.New()
err = r.OpenDB("rdpg")
if err != nil {
log.Error(fmt.Sprintf("Failed fetching catalog from database: %s", err))
return
}
db := r.DB
err = db.Select(&c.Services, `SELECT service_id,name,description,bindable FROM cfsb.services;`)
if err != nil {
log.Error(fmt.Sprintf("Catalog#Fetch() selecting from cfsb.services %s", err.Error()))
return
}
// TODO: Account for plans being associated with a service.
for i, _ := range c.Services {
service := &c.Services[i]
err = db.Select(&service.Plans, `SELECT plan_id,name,description FROM cfsb.plans;`)
if err != nil {
log.Error(fmt.Sprintf("Catalog#Fetch() Service Plans %s", err.Error()))
return
}
c.Services[i].Tags = []string{"rdpg", "postgresql"}
// c.Services[i].Dashboard = DashboardClient{}
}
return
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:28,代码来源:catalog.go
示例4: CreateDatabase
func (n *Node) CreateDatabase(dbname, owner string) (err error) {
n.Database = "postgres"
db, err := n.Connect()
if err != nil {
log.Error(fmt.Sprintf("Node#CreateDatabase(%s) %s ! %s", dbname, n.Host, err))
return
}
defer db.Close()
sq := fmt.Sprintf(`CREATE DATABASE %s WITH OWNER %s TEMPLATE template0 ENCODING 'UTF8'`, dbname, owner)
log.Trace(fmt.Sprintf(`Node#CreateDatabase(%s) %s > %s`, dbname, n.Host, sq))
_, err = db.Query(sq)
if err != nil {
log.Error(fmt.Sprintf("Node#CreateDatabase(%s) %s ! %s", dbname, n.Host, err))
return
}
sq = fmt.Sprintf(`REVOKE ALL ON DATABASE "%s" FROM public`, dbname)
log.Trace(fmt.Sprintf(`Node#CreateDatabase(%s) %s > %s`, dbname, n.Host, sq))
_, err = db.Exec(sq)
if err != nil {
log.Error(fmt.Sprintf("Node#CreateDatabase(%s) %s ! %s", dbname, n.Host, err))
}
sq = fmt.Sprintf(`GRANT ALL PRIVILEGES ON DATABASE %s TO %s`, dbname, owner)
log.Trace(fmt.Sprintf(`Node#CreateDatabase(%s) %s > %s`, dbname, n.Host, sq))
_, err = db.Query(sq)
if err != nil {
log.Error(fmt.Sprintf(`Node#CreateDatabase(%s) %s ! %s`, dbname, n.Host, err))
return
}
return nil
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:33,代码来源:node.go
示例5: CatalogHandler
/*
(FC) GET /v2/catalog
*/
func CatalogHandler(w http.ResponseWriter, request *http.Request) {
log.Trace(fmt.Sprintf("%s /v2/catalog", request.Method))
switch request.Method {
case "GET":
c := Catalog{}
err := c.Fetch()
if err != nil {
msg := fmt.Sprintf(`{"status": %d, "description": "%s"}`, http.StatusInternalServerError, err)
log.Error(msg)
http.Error(w, msg, http.StatusInternalServerError)
return
}
jsonCatalog, err := json.Marshal(c)
if err != nil {
msg := fmt.Sprintf(`{"status": %d, "description": "%s"}`, http.StatusInternalServerError, err)
log.Error(msg)
http.Error(w, msg, http.StatusInternalServerError)
} else {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
w.Write(jsonCatalog)
}
default:
msg := fmt.Sprintf(`{"status": %d, "description": "Allowed Methods: GET"}`, http.StatusMethodNotAllowed)
log.Error(msg)
http.Error(w, msg, http.StatusMethodNotAllowed)
}
return
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:32,代码来源:api.go
示例6: CreateUser
func (r *RDPG) CreateUser(username, password string) (err error) {
for _, node := range r.Nodes() {
node.Database = `postgres`
db, err := node.Connect()
if err != nil {
log.Error(fmt.Sprintf(`RDPG#CreateUser(%s) %s ! %s`, username, node.Host, err))
return err
}
// TODO: Check if user exists first
sq := fmt.Sprintf(`CREATE USER %s;`, username)
log.Trace(fmt.Sprintf(`RDPG#CreateUser(%s) %s > %s`, username, node.Host, sq))
_, err = db.Exec(sq)
if err != nil {
log.Error(fmt.Sprintf("RDPG#CreateUser(%s) %s ! %s", username, node.Host, err))
db.Close()
return err
}
sq = fmt.Sprintf(`ALTER USER %s ENCRYPTED PASSWORD '%s'`, username, password)
log.Trace(fmt.Sprintf(`RDPG#CreateUser(%s) %s > %s`, username, node.Host, sq))
_, err = db.Exec(sq)
if err != nil {
log.Error(fmt.Sprintf("RDPG#CreateUser(%s) %s ! %s", username, node.Host, err))
}
db.Close()
}
return nil
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:29,代码来源:bdr.go
示例7: ServiceHandler
/*
POST /services/{service}/{action}
*/
func ServiceHandler(w http.ResponseWriter, request *http.Request) {
vars := mux.Vars(request)
log.Trace(fmt.Sprintf("%s /services/%s/%s", request.Method, vars["service"], vars["action"]))
switch request.Method {
case "PUT":
service, err := NewService(vars["service"])
if err != nil {
log.Error(fmt.Sprintf("ServiceHandler(): NewService(%s)"))
http.Error(w, `{"status": %d, "description": "%s"}`, http.StatusInternalServerError)
return
}
switch vars["action"] {
case "configure":
err := service.Configure()
if err != nil {
msg := fmt.Sprintf(`{"status": %d, "description": "%s"}`, http.StatusInternalServerError, err)
log.Error(msg)
http.Error(w, msg, http.StatusInternalServerError)
}
msg := fmt.Sprintf(`{"status": %d, "description": "%s %s"}`, http.StatusOK, vars["service"], vars["action"])
log.Trace(msg)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, msg)
default:
msg := fmt.Sprintf(`{"status": %d, "description": "Invalid Action %s for %s"}`, http.StatusBadRequest, vars["action"], vars["service"])
log.Error(msg)
http.Error(w, msg, http.StatusBadRequest)
}
default:
msg := fmt.Sprintf(`{"status": %d, "description": "Method not allowed %s"}`, http.StatusMethodNotAllowed, request.Method)
log.Error(msg)
http.Error(w, msg, http.StatusMethodNotAllowed)
}
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:38,代码来源:api.go
示例8: DropDatabase
func (r *RDPG) DropDatabase(dbname string) (err error) {
nodes := r.Nodes()
for i := len(nodes) - 1; i >= 0; i-- {
node := nodes[i]
node.Database = "postgres"
db, err := node.Connect()
if err != nil {
log.Error(fmt.Sprintf("RDPG#DropDatabase(%s) %s ! %s", dbname, node.Host, err))
return err
}
// sq := fmt.Sprintf(SELECT slot_name FROM pg_replication_slots WHERE database='%s',dbname);
// pg_recvlogical --drop-slot
// TODO: How do we drop a database in bdr properly?
sq := fmt.Sprintf(`DROP DATABASE IF EXISTS %s`, dbname)
log.Trace(fmt.Sprintf(`RDPG#DropDatabase(%s) %s DROP > %s`, dbname, node.Host, sq))
_, err = db.Exec(sq)
if err != nil {
log.Error(fmt.Sprintf("RDPG#DropDatabase(%s) DROP %s ! %s", dbname, node.Host, err))
}
db.Close()
}
return nil
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:26,代码来源:bdr.go
示例9: connect
func (r *RDPG) connect() (db *sqlx.DB, err error) {
db, err = sqlx.Connect("postgres", r.URI)
if err != nil {
log.Error(fmt.Sprintf("rdpg.Node#Connect() %s ! %s", r.URI, err))
}
return db, err
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:7,代码来源:bdr.go
示例10: NewRDPG
// TODO: RDPG Struct => RDPG Struct, allowing for multiple instances of RDPG
func NewRDPG(uri string) *RDPG {
if uri == "" || uri[0:13] != "postgresql://" {
log.Error(fmt.Sprintf("rdpg.NewRDPG() uri malformed ! %s", uri))
return nil
}
return &RDPG{URI: uri}
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:8,代码来源:bdr.go
示例11: RemoveBinding
func RemoveBinding(bindingId string) (binding *Binding, err error) {
binding, err = FindBinding(bindingId)
if err != nil {
log.Error(fmt.Sprintf(`cfsb.CreateBinding(%s) ! %s`, bindingId, err))
return
}
r := rdpg.New()
sq := `UPDATE cfsb.bindings SET ineffective_at = CURRENT_TIMESTAMP WHERE binding_id = $1;`
log.Trace(fmt.Sprintf(`cfsb.RemoveBinding(%s) > %s`, bindingId, sq))
r.OpenDB("rdpg")
_, err = r.DB.Query(sq, bindingId)
if err != nil {
log.Error(fmt.Sprintf(`cfsb.CreateBinding(%s) ! %s`, bindingId, err))
}
r.DB.Close()
return
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:17,代码来源:bindings.go
示例12: Connect
func (n *Node) Connect() (db *sqlx.DB, err error) {
uri := n.URI()
db, err = sqlx.Connect(`postgres`, uri) // n.LocalDSN)
if err != nil {
log.Error(fmt.Sprintf(`rdpg.Node#Connect() %s ! %s`, uri, err))
return db, err
}
return db, nil
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:9,代码来源:node.go
示例13: Provision
func (i *Instance) Provision() (err error) {
i.Pass = strings.ToLower(strings.Replace(rdpg.NewUUID().String(), "-", "", -1))
r := rdpg.New()
// TODO: Alter this logic based on "plan"
err = r.CreateUser(i.User, i.Pass)
if err != nil {
log.Error(fmt.Sprintf("Instance#Provision(%s) CreateUser(%s) ! %s", i.InstanceId, i.User, err))
return err
}
err = r.CreateDatabase(i.Database, i.User)
if err != nil {
log.Error(fmt.Sprintf("Instance#Provision(%s) CreateDatabase(%s,%s) ! %s", i.InstanceId, i.Database, i.User, err))
return err
}
err = r.CreateReplicationGroup(i.Database)
if err != nil {
log.Error(fmt.Sprintf("Instance#Provision(%s) CreateReplicationGroup(%s) ! %s", i.InstanceId, i.Database, err))
return err
}
r.OpenDB("rdpg")
sq := `INSERT INTO cfsb.instances
(instance_id, service_id, plan_id, organization_id, space_id, dbname, uname, pass)
VALUES ($1,$2,$3,$4,$5,$6,$7,$8);
`
_, err = r.DB.Query(sq, i.InstanceId, i.ServiceId, i.PlanId, i.OrganizationId, i.SpaceId, i.Database, i.User, i.Pass)
if err != nil {
log.Error(fmt.Sprintf(`Instance#Provision(%s) ! %s`, i.InstanceId, err))
}
nodes := r.Nodes()
for _, node := range nodes {
err := node.AdminAPI("PUT", "services/pgbouncer/configure")
if err != nil {
log.Error(fmt.Sprintf(`Instance#Provision(%s) %s ! %s`, i.InstanceId, node.Host, err))
}
}
r.DB.Close()
return nil
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:43,代码来源:instances.go
示例14: Remove
func (i *Instance) Remove() (err error) {
r := rdpg.New()
r.OpenDB("rdpg")
_, err = r.DB.Exec(`UPDATE cfsb.instances SET ineffective_at = CURRENT_TIMESTAMP WHERE id=$1`, i.Id)
if err != nil {
log.Error(fmt.Sprintf("Instance#Remove(%s) ! %s", i.InstanceId, err))
}
time.Sleep(1) // Wait for the update to propigate to the other nodes.
for _, node := range r.Nodes() {
err := node.AdminAPI("PUT", "services/pgbouncer/configure")
if err != nil {
log.Error(fmt.Sprintf(`Instance#Provision(%s) %s ! %s`, i.InstanceId, node.Host, err))
}
}
r.DB.Close()
return
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:19,代码来源:instances.go
示例15: CreateUser
func (n *Node) CreateUser(name, password string) (err error) {
if n.User != `postgres` {
return errors.New(fmt.Sprintf(`Node user is not postgres, can not create a user with '%s'`, n.User))
}
uri := n.URI()
db, err := sqlx.Connect(`postgres`, uri)
if err != nil {
log.Error(fmt.Sprintf(`Node#CreateUser(%s) %s ! %s`, name, uri, err))
return err
}
defer db.Close()
err = db.Get(&name, `SELECT rolname FROM pg_roles WHERE rolname=? LIMIT 1;`, name)
if err != nil {
log.Error(fmt.Sprintf(`Node#CreateUser(%s) %s ! %s`, name, n.Host, err))
return err
}
if name != "" {
log.Debug(fmt.Sprintf(`User %s already exists, skipping.`, name))
return nil
}
sq := fmt.Sprintf(`CREATE USER %s WITH SUPERUSER CREATEDB CREATEROLE INHERIT;`, name)
result, err := db.Exec(sq)
rows, _ := result.RowsAffected()
if rows > 0 {
log.Debug(fmt.Sprintf(`Node#CreateUser(%s) %s User Created`, n.Host, name))
}
if err != nil {
log.Error(fmt.Sprintf(`Node#CreateUser(%s) %s ! %s`, name, n.Host, err))
return err
}
sq = fmt.Sprintf(`ALTER USER %s ENCRYPTED PASSWORD %s;`, name, password)
_, err = db.Exec(sq)
if err != nil {
log.Error(fmt.Sprintf(`Node#CreateUser(%s) %s ! %s`, name, n.Host, err))
return err
}
return nil
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:42,代码来源:node.go
示例16: CreateBinding
func CreateBinding(instanceId, bindingId string) (binding *Binding, err error) {
instance, err := FindInstance(instanceId)
if err != nil {
log.Error(fmt.Sprintf(`cfsb.CreateBinding(%s,%s) ! %s`, instanceId, bindingId, err))
return
}
binding = &Binding{BindingId: bindingId, InstanceId: instanceId}
dns := instance.ExternalDNS()
s := strings.Split(dns, ":")
binding.Creds = Credentials{
URI: instance.URI(),
DSN: instance.DSN(),
JDBCURI: "jdbc:" + instance.URI(),
Host: s[0],
Port: s[1],
UserName: instance.User,
Password: instance.Pass,
Database: instance.Database,
}
r := rdpg.New()
r.OpenDB("rdpg")
sq := `INSERT INTO cfsb.bindings (instance_id,binding_id) VALUES ($1,$2);`
_, err = r.DB.Query(sq, binding.InstanceId, binding.BindingId)
if err != nil {
log.Error(fmt.Sprintf(`cfsb.CreateBinding(%s) ! %s`, bindingId, err))
}
sq = `INSERT INTO cfsb.credentials (instance_id,binding_id,host,port,uname,pass,dbname) VALUES ($1,$2,$3,$4,$5,$6,$7);`
_, err = r.DB.Query(sq, binding.InstanceId, binding.BindingId, binding.Creds.Host, binding.Creds.Port, binding.Creds.UserName, binding.Creds.Password, binding.Creds.Database)
if err != nil {
log.Error(fmt.Sprintf(`cfsb.CreateBinding(%s) ! %s`, bindingId, err))
}
r.DB.Close()
return
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:41,代码来源:bindings.go
示例17: CreateExtensions
func (n *Node) CreateExtensions(exts []string) (err error) {
db, err := n.Connect()
if err != nil {
log.Error(fmt.Sprintf("Node#CreateExtensions() %s ! %s", n.URI(), err))
return
}
defer db.Close()
_, err = db.Query(`CREATE EXTENSION IF NOT EXISTS btree_gist`)
if err != nil {
log.Error(fmt.Sprintf("Node#CreateExtensions() %s ! %s", n.Host, err))
return
}
_, err = db.Query(`CREATE EXTENSION IF NOT EXISTS bdr`)
if err != nil {
log.Error(fmt.Sprintf("Node#CreateExtensions() %s ! %s", n.Host, err))
return
}
return
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:21,代码来源:node.go
示例18: FindPlan
func FindPlan(planId string) (plan *Plan, err error) {
r := rdpg.New()
r.OpenDB("rdpg")
plan = &Plan{}
sq := `SELECT id,name,description FROM cfsb.plans WHERE id=$1 LIMIT 1;`
err = r.DB.Get(&plan, sq, planId)
if err != nil {
log.Error(fmt.Sprintf("cfsb.FindPlan(%s) %s", planId, err))
}
r.DB.Close()
return plan, err
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:12,代码来源:plans.go
示例19: DropUser
func (r *RDPG) DropUser(name string) (err error) {
nodes := r.Nodes()
for i := len(nodes) - 1; i >= 0; i-- {
node := nodes[i]
node.Database = "postgres"
db, err := node.Connect()
if err != nil {
log.Error(fmt.Sprintf("RDPG#DropUser(%s) %s ! %s", name, node.Host, err))
return err
}
sq := fmt.Sprintf(`DROP USER %s`, name)
log.Trace(fmt.Sprintf(`RDPG#DropUser(%s) %s > %s`, name, node.Host, sq))
_, err = db.Exec(sq)
if err != nil {
log.Error(fmt.Sprintf("RDPG#DropUser(%s) %s ! %s", name, node.Host, err))
}
db.Close()
}
return nil
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:22,代码来源:bdr.go
示例20: Nodes
func (r *RDPG) Nodes() (nodes []Node) {
db, err := r.connect()
if err != nil {
log.Error(fmt.Sprintf("RDPG#Nodes() ! %s", err))
}
// TODO: Populate list of rdpg nodes for given URL,
//`SELECT node_local_dsn FROM bdr.bdr_nodes INTO rdpg.nodes (node_local_dsn);`
type dsn struct {
DSN string `db:"node_local_dsn"`
}
dsns := []dsn{}
err = db.Select(&dsns, SQL["bdr_nodes_dsn"])
if err != nil {
log.Error(fmt.Sprintf("RDPG#Nodes() %s ! %s", SQL["bdr_nodes"], err))
}
for _, t := range dsns {
node := Node{}
s := strings.Split(t.DSN, " ")
node.LocalDSN = t.DSN
node.Host = strings.Split(s[0], "=")[1]
node.Port = strings.Split(s[1], "=")[1]
node.User = strings.Split(s[2], "=")[1]
node.Database = `postgres` // strings.Split(s[3], "=")[1]
nodes = append(nodes, node)
}
// TODO: Get this information into the database and then out of the rdpg.nodes
//rows, err := db.Query("SELECT host,port,user,'postgres' FROM rdpg.nodes;")
//if err != nil {
// log.Error(fmt.Sprintf("Nodes() %s", err))
//} else {
// sqlx.StructScan(rows, nodes)
//}
db.Close()
return nodes
}
开发者ID:longnguyen11288,项目名称:rdpgd,代码行数:39,代码来源:bdr.go
注:本文中的github.com/wayneeseguin/rdpg-agent/log.Error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论