本文整理汇总了Golang中github.com/theckman/goiardi/datastore.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:theckman,项目名称:goiardi,代码行数:30,代码来源:role.go
示例2: 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
}
开发者ID:theckman,项目名称:goiardi,代码行数:32,代码来源:report.go
示例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
}
开发者ID:theckman,项目名称:goiardi,代码行数:37,代码来源:environment.go
示例4: 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
}
开发者ID:theckman,项目名称:goiardi,代码行数:33,代码来源:report.go
示例5: 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)
}
开发者ID:theckman,项目名称:goiardi,代码行数:8,代码来源:log_info.go
示例6: 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
}
开发者ID:theckman,项目名称:goiardi,代码行数:35,代码来源:databag.go
示例7: Save
// Save a file store item.
func (f *FileStore) Save() error {
if config.Config.UseMySQL {
err := f.saveMySQL()
if err != nil {
return err
}
} else if config.Config.UsePostgreSQL {
err := f.savePostgreSQL()
if err != nil {
return nil
}
} else {
ds := datastore.New()
ds.Set("filestore", f.Chksum, f)
}
if config.Config.LocalFstoreDir != "" {
fp, err := os.Create(path.Join(config.Config.LocalFstoreDir, f.Chksum))
if err != nil {
return err
}
defer fp.Close()
_, err = fp.Write(*f.Data)
if err != nil {
return err
}
return fp.Close()
}
return nil
}
开发者ID:theckman,项目名称:goiardi,代码行数:30,代码来源:filestore.go
示例8: 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
}
开发者ID:theckman,项目名称:goiardi,代码行数:32,代码来源:client.go
示例9: Get
// Get a node.
func Get(nodeName string) (*Node, util.Gerror) {
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, util.CastErr(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 := util.Errorf("node '%s' not found", nodeName)
err.SetStatus(http.StatusNotFound)
return nil, err
}
return node, nil
}
开发者ID:theckman,项目名称:goiardi,代码行数:31,代码来源:node.go
示例10: New
// New creates an empty data bag, and kicks off adding it to the index.
func New(name string) (*DataBag, util.Gerror) {
var found bool
var err util.Gerror
if err = validateDataBagName(name, false); err != nil {
return nil, err
}
if config.UsingDB() {
var cerr error
found, cerr = checkForDataBagSQL(datastore.Dbh, name)
if cerr != nil {
err = util.Errorf(cerr.Error())
err.SetStatus(http.StatusInternalServerError)
return nil, err
}
} else {
ds := datastore.New()
_, found = ds.Get("data_bag", name)
}
if found {
err = util.Errorf("Data bag %s already exists", name)
err.SetStatus(http.StatusConflict)
return nil, err
}
dbiMap := make(map[string]*DataBagItem)
dataBag := &DataBag{
Name: name,
DataBagItems: dbiMap,
}
indexer.CreateNewCollection(name)
return dataBag, nil
}
开发者ID:theckman,项目名称:goiardi,代码行数:35,代码来源:databag.go
示例11: New
// New creates a new cookbook.
func New(name string) (*Cookbook, util.Gerror) {
var found bool
if !util.ValidateName(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
}
开发者ID:theckman,项目名称:goiardi,代码行数:29,代码来源:cookbook.go
示例12: 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
}
开发者ID:theckman,项目名称:goiardi,代码行数:32,代码来源:sandbox.go
示例13: 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
}
开发者ID:theckman,项目名称:goiardi,代码行数:30,代码来源:user.go
示例14: 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
}
开发者ID:theckman,项目名称:goiardi,代码行数:26,代码来源:log_info.go
示例15: Delete
// Delete a logged event.
func (le *LogInfo) Delete() error {
if config.UsingDB() {
return le.deleteSQL()
}
ds := datastore.New()
ds.DeleteLogInfo(le.ID)
return nil
}
开发者ID:theckman,项目名称:goiardi,代码行数:9,代码来源:log_info.go
示例16: AllShoveyIDs
// AllShoveyIDs returns all shovey run ids.
func AllShoveyIDs() ([]string, util.Gerror) {
if config.UsingDB() {
return allShoveyIDsSQL()
}
ds := datastore.New()
list := ds.GetList("shovey")
return list, nil
}
开发者ID:theckman,项目名称:goiardi,代码行数:9,代码来源:shovey.go
示例17: Delete
// Delete a report.
func (r *Report) Delete() error {
if config.UsingDB() {
return r.deleteSQL()
}
ds := datastore.New()
ds.Delete("report", r.RunID)
return nil
}
开发者ID:theckman,项目名称:goiardi,代码行数:9,代码来源:report.go
示例18: GetList
// GetList gets a list of all cookbooks on this server.
func GetList() []string {
if config.UsingDB() {
return getCookbookListSQL()
}
ds := datastore.New()
cbList := ds.GetList("cookbook")
return cbList
}
开发者ID:theckman,项目名称:goiardi,代码行数:9,代码来源:cookbook.go
示例19: deleteStatuses
func (n *Node) deleteStatuses() error {
if config.UsingDB() {
err := fmt.Errorf("not needed in SQL mode - foreign keys handle deleting node statuses")
return err
}
ds := datastore.New()
return ds.DeleteNodeStatus(n.Name)
}
开发者ID:theckman,项目名称:goiardi,代码行数:8,代码来源:status.go
示例20: importSave
func (s *Shovey) importSave() error {
if config.UsingDB() {
return s.importSaveSQL()
}
ds := datastore.New()
ds.Set("shovey", s.RunID, s)
return nil
}
开发者ID:theckman,项目名称:goiardi,代码行数:8,代码来源:shovey.go
注:本文中的github.com/theckman/goiardi/datastore.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论