本文整理汇总了Golang中github.com/ctdk/goiardi/config.UsingDB函数的典型用法代码示例。如果您正苦于以下问题:Golang UsingDB函数的具体用法?Golang UsingDB怎么用?Golang UsingDB使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UsingDB函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Get
// Get a role.
func Get(roleName string) (*Role, error) {
var role *Role
var found bool
if config.UsingDB() {
var err error
role, err = getSQL(roleName)
if err != nil {
if err == sql.ErrNoRows {
found = false
} else {
return nil, err
}
} else {
found = true
}
} else {
ds := datastore.New()
var r interface{}
r, found = ds.Get("role", roleName)
if r != nil {
role = r.(*Role)
}
}
if !found {
err := fmt.Errorf("Cannot load role %s", roleName)
return nil, err
}
return role, nil
}
示例2: handleSignals
func handleSignals() {
c := make(chan os.Signal, 1)
// SIGTERM is not exactly portable, but Go has a fake signal for it
// with Windows so it being there should theoretically not break it
// running on windows
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
// if we receive a SIGINT or SIGTERM, do cleanup here.
go func() {
for sig := range c {
if sig == os.Interrupt || sig == syscall.SIGTERM {
logger.Infof("cleaning up...")
if config.Config.FreezeData {
if config.Config.DataStoreFile != "" {
ds := datastore.New()
if err := ds.Save(config.Config.DataStoreFile); err != nil {
logger.Errorf(err.Error())
}
}
if err := indexer.SaveIndex(config.Config.IndexFile); err != nil {
logger.Errorf(err.Error())
}
}
if config.UsingDB() {
datastore.Dbh.Close()
}
os.Exit(0)
} else if sig == syscall.SIGHUP {
logger.Infof("Reloading configuration...")
config.ParseConfigOptions()
}
}
}()
}
示例3: New
// New creates a new environment, returning an error if the environment already
// exists or you try to create an environment named "_default".
func New(name string) (*ChefEnvironment, util.Gerror) {
if !util.ValidateEnvName(name) {
err := util.Errorf("Field 'name' invalid")
err.SetStatus(http.StatusBadRequest)
return nil, err
}
var found bool
if config.UsingDB() {
var eerr error
found, eerr = checkForEnvironmentSQL(datastore.Dbh, name)
if eerr != nil {
err := util.CastErr(eerr)
err.SetStatus(http.StatusInternalServerError)
return nil, err
}
} else {
ds := datastore.New()
_, found = ds.Get("env", name)
}
if found || name == "_default" {
err := util.Errorf("Environment already exists")
return nil, err
}
env := &ChefEnvironment{
Name: name,
ChefType: "environment",
JSONClass: "Chef::Environment",
Default: map[string]interface{}{},
Override: map[string]interface{}{},
CookbookVersions: map[string]string{},
}
return env, nil
}
示例4: New
// New creates a new cookbook.
func New(name string) (*Cookbook, util.Gerror) {
var found bool
if !util.ValidateEnvName(name) {
err := util.Errorf("Invalid cookbook name '%s' using regex: 'Malformed cookbook name. Must only contain A-Z, a-z, 0-9, _ or -'.", name)
return nil, err
}
if config.UsingDB() {
var cerr error
found, cerr = checkForCookbookSQL(datastore.Dbh, name)
if cerr != nil {
err := util.CastErr(cerr)
err.SetStatus(http.StatusInternalServerError)
return nil, err
}
} else {
ds := datastore.New()
_, found = ds.Get("cookbook", name)
}
if found {
err := util.Errorf("Cookbook %s already exists", name)
err.SetStatus(http.StatusConflict)
}
cookbook := &Cookbook{
Name: name,
Versions: make(map[string]*CookbookVersion),
}
return cookbook, nil
}
示例5: Get
// Get a report.
func Get(runID string) (*Report, util.Gerror) {
var report *Report
var found bool
if config.UsingDB() {
var err error
report, err = getReportSQL(runID)
if err != nil {
if err == sql.ErrNoRows {
found = false
} else {
gerr := util.CastErr(err)
gerr.SetStatus(http.StatusInternalServerError)
return nil, gerr
}
} else {
found = true
}
} else {
ds := datastore.New()
var r interface{}
r, found = ds.Get("report", runID)
if r != nil {
report = r.(*Report)
}
}
if !found {
err := util.Errorf("Report %s not found", runID)
err.SetStatus(http.StatusNotFound)
return nil, err
}
return report, nil
}
示例6: Get
// Get a node.
func Get(nodeName string) (*Node, error) {
var node *Node
var found bool
if config.UsingDB() {
var err error
node, err = getSQL(nodeName)
if err != nil {
if err == sql.ErrNoRows {
found = false
} else {
return nil, err
}
} else {
found = true
}
} else {
ds := datastore.New()
var n interface{}
n, found = ds.Get("node", nodeName)
if n != nil {
node = n.(*Node)
}
}
if !found {
err := fmt.Errorf("node '%s' not found", nodeName)
return nil, err
}
return node, nil
}
示例7: sortedVersions
/* Returns a sorted list of all the versions of this cookbook */
func (c *Cookbook) sortedVersions() []*CookbookVersion {
if config.UsingDB() {
return c.sortedCookbookVersionsSQL()
}
sorted := make([]*CookbookVersion, len(c.Versions))
keys := make(VersionStrings, len(c.Versions))
u := 0
for k, cbv := range c.Versions {
keys[u] = k
u++
datastore.ChkNilArray(cbv)
}
sort.Sort(sort.Reverse(keys))
/* populate sorted now */
for i, s := range keys {
/* This shouldn't be able to happen, but somehow it... does? */
if i >= len(sorted) {
break
}
sorted[i] = c.Versions[s]
}
return sorted
}
示例8: Get
// Get a sandbox.
func Get(sandboxID string) (*Sandbox, error) {
var sandbox *Sandbox
var found bool
if config.UsingDB() {
var err error
sandbox, err = getSQL(sandboxID)
if err != nil {
if err == sql.ErrNoRows {
found = false
} else {
return nil, err
}
} else {
found = true
}
} else {
ds := datastore.New()
var s interface{}
s, found = ds.Get("sandbox", sandboxID)
if s != nil {
sandbox = s.(*Sandbox)
}
}
if !found {
err := fmt.Errorf("Sandbox %s not found", sandboxID)
return nil, err
}
return sandbox, nil
}
示例9: DeleteVersion
// DeleteVersion deletes a particular version of a cookbook.
func (c *Cookbook) DeleteVersion(cbVersion string) util.Gerror {
/* Check for existence */
cbv, _ := c.GetVersion(cbVersion)
if cbv == nil {
err := util.Errorf("Version %s of cookbook %s does not exist to be deleted.", cbVersion, c.Name)
err.SetStatus(http.StatusNotFound)
return err
}
fhashes := cbv.fileHashes()
if config.UsingDB() {
err := cbv.deleteCookbookVersionSQL()
if err != nil {
return nil
}
}
c.numVersions = nil
delete(c.Versions, cbVersion)
c.Save()
c.deleteHashes(fhashes)
return nil
}
示例10: Get
// Get a user.
func Get(name string) (*User, util.Gerror) {
var user *User
if config.UsingDB() {
var err error
user, err = getUserSQL(name)
if err != nil {
var gerr util.Gerror
if err != sql.ErrNoRows {
gerr = util.Errorf(err.Error())
gerr.SetStatus(http.StatusInternalServerError)
} else {
gerr = util.Errorf("Client %s not found", name)
gerr.SetStatus(http.StatusNotFound)
}
return nil, gerr
}
} else {
ds := datastore.New()
u, found := ds.Get("user", name)
if !found {
err := util.Errorf("User %s not found", name)
return nil, err
}
if u != nil {
user = u.(*User)
}
}
return user, nil
}
示例11: Get
// Get gets a client from the data store.
func Get(clientname string) (*Client, util.Gerror) {
var client *Client
var err error
if config.UsingDB() {
client, err = getClientSQL(clientname)
if err != nil {
var gerr util.Gerror
if err != sql.ErrNoRows {
gerr = util.Errorf(err.Error())
gerr.SetStatus(http.StatusInternalServerError)
} else {
gerr = util.Errorf("Client %s not found", clientname)
gerr.SetStatus(http.StatusNotFound)
}
return nil, gerr
}
} else {
ds := datastore.New()
c, found := ds.Get("client", clientname)
if !found {
gerr := util.Errorf("Client %s not found", clientname)
gerr.SetStatus(http.StatusNotFound)
return nil, gerr
}
if c != nil {
client = c.(*Client)
}
}
return client, nil
}
示例12: New
// New creates a new report.
func New(runID string, nodeName string) (*Report, util.Gerror) {
var found bool
if config.UsingDB() {
var err error
found, err = checkForReportSQL(datastore.Dbh, runID)
if err != nil {
gerr := util.CastErr(err)
gerr.SetStatus(http.StatusInternalServerError)
return nil, gerr
}
} else {
ds := datastore.New()
_, found = ds.Get("report", runID)
}
if found {
err := util.Errorf("Report already exists")
err.SetStatus(http.StatusConflict)
return nil, err
}
if u := uuid.Parse(runID); u == nil {
err := util.Errorf("run id was not a valid uuid")
err.SetStatus(http.StatusBadRequest)
return nil, err
}
report := &Report{
RunID: runID,
NodeName: nodeName,
Status: "started",
}
return report, nil
}
示例13: Get
// Get a particular event by its id.
func Get(id int) (*LogInfo, error) {
var le *LogInfo
if config.UsingDB() {
var err error
le, err = getLogEventSQL(id)
if err != nil {
if err == sql.ErrNoRows {
err = fmt.Errorf("Couldn't find log event with id %d", id)
}
return nil, err
}
} else {
ds := datastore.New()
c, err := ds.GetLogInfo(id)
if err != nil {
return nil, err
}
if c != nil {
le = c.(*LogInfo)
le.ID = id
}
}
return le, nil
}
示例14: PurgeLogInfos
// PurgeLogInfos removes all logged events before the given id.
func PurgeLogInfos(id int) (int64, error) {
if config.UsingDB() {
return purgeSQL(id)
}
ds := datastore.New()
return ds.PurgeLogInfoBefore(id)
}
示例15: Get
// Get a data bag.
func Get(dbName string) (*DataBag, util.Gerror) {
var dataBag *DataBag
var err error
if config.UsingDB() {
dataBag, err = getDataBagSQL(dbName)
if err != nil {
var gerr util.Gerror
if err == sql.ErrNoRows {
gerr = util.Errorf("Cannot load data bag %s", dbName)
gerr.SetStatus(http.StatusNotFound)
} else {
gerr = util.Errorf(err.Error())
gerr.SetStatus(http.StatusInternalServerError)
}
return nil, gerr
}
} else {
ds := datastore.New()
d, found := ds.Get("data_bag", dbName)
if !found {
err := util.Errorf("Cannot load data bag %s", dbName)
err.SetStatus(http.StatusNotFound)
return nil, err
}
if d != nil {
dataBag = d.(*DataBag)
for _, v := range dataBag.DataBagItems {
z := datastore.WalkMapForNil(v.RawData)
v.RawData = z.(map[string]interface{})
}
}
}
return dataBag, nil
}