當前位置: 首頁>>代碼示例>>Golang>>正文


Golang types.Resource類代碼示例

本文整理匯總了Golang中github.com/flynn/flynn/controller/types.Resource的典型用法代碼示例。如果您正苦於以下問題:Golang Resource類的具體用法?Golang Resource怎麽用?Golang Resource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Resource類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: PutResource

func (c *controllerAPI) PutResource(ctx context.Context, w http.ResponseWriter, req *http.Request) {
	params, _ := ctxhelper.ParamsFromContext(ctx)

	p, err := c.getProvider(ctx)
	if err != nil {
		respondWithError(w, err)
		return
	}

	var resource ct.Resource
	if err = httphelper.DecodeJSON(req, &resource); err != nil {
		respondWithError(w, err)
		return
	}

	resource.ID = params.ByName("resources_id")
	resource.ProviderID = p.ID

	if err := schema.Validate(resource); err != nil {
		respondWithError(w, err)
		return
	}

	if err := c.resourceRepo.Add(&resource); err != nil {
		respondWithError(w, err)
		return
	}
	httphelper.JSON(w, 200, &resource)
}
開發者ID:ably-forks,項目名稱:flynn,代碼行數:29,代碼來源:resource.go

示例2: putResource

func putResource(p *ct.Provider, params martini.Params, resource ct.Resource, repo *ResourceRepo, r ResponseHelper) {
	resource.ID = params["resources_id"]
	resource.ProviderID = p.ID
	if err := repo.Add(&resource); err != nil {
		r.Error(err)
		return
	}
	r.JSON(200, &resource)
}
開發者ID:kelsieflynn,項目名稱:seraphilos,代碼行數:9,代碼來源:controller.go

示例3: Add

func (rr *ResourceRepo) Add(r *ct.Resource) error {
	if r.ID == "" {
		r.ID = random.UUID()
	}
	tx, err := rr.db.Begin()
	if err != nil {
		return err
	}
	err = tx.QueryRow(`INSERT INTO resources (resource_id, provider_id, external_id, env)
					   VALUES ($1, $2, $3, $4)
					   RETURNING created_at`,
		r.ID, r.ProviderID, r.ExternalID, envHstore(r.Env)).Scan(&r.CreatedAt)
	if err != nil {
		tx.Rollback()
		return err
	}
	for i, appID := range r.Apps {
		var filterSQL string
		var args []interface{}
		if idPattern.MatchString(appID) {
			filterSQL = "app_id = $1 OR name = $2), $3)"
			args = []interface{}{appID, appID, r.ID}
		} else {
			filterSQL = "name = $1), $2)"
			args = []interface{}{appID, r.ID}
		}
		err = tx.QueryRow("INSERT INTO app_resources (app_id, resource_id) VALUES ((SELECT app_id FROM apps WHERE "+
			filterSQL+" RETURNING app_id", args...).Scan(&r.Apps[i])
		if err != nil {
			tx.Rollback()
			return err
		}
		r.Apps[i] = cleanUUID(r.Apps[i])
	}
	r.ID = cleanUUID(r.ID)
	return tx.Commit()
}
開發者ID:ericcapricorn,項目名稱:flynn,代碼行數:37,代碼來源:resource.go

示例4: Add

func (rr *ResourceRepo) Add(r *ct.Resource) error {
	if r.ID == "" {
		r.ID = random.UUID()
	}
	tx, err := rr.db.Begin()
	if err != nil {
		return err
	}
	err = tx.QueryRow("resource_insert", r.ID, r.ProviderID, r.ExternalID, r.Env).Scan(&r.CreatedAt)
	if err != nil {
		tx.Rollback()
		return err
	}
	for i, appID := range r.Apps {
		var row postgres.Scanner
		if idPattern.MatchString(appID) {
			row = tx.QueryRow("app_resource_insert_app_by_name_or_id", appID, appID, r.ID)
		} else {
			row = tx.QueryRow("app_resource_insert_app_by_name", appID, r.ID)
		}
		if err := row.Scan(&r.Apps[i]); err != nil {
			tx.Rollback()
			return err
		}
	}
	for _, appID := range r.Apps {
		if err := createEvent(tx.Exec, &ct.Event{
			AppID:      appID,
			ObjectID:   r.ID,
			ObjectType: ct.EventTypeResource,
		}, r); err != nil {
			tx.Rollback()
			return err
		}
	}
	if len(r.Apps) == 0 {
		// Ensure an event is created if there are no associated apps
		if err := createEvent(tx.Exec, &ct.Event{
			ObjectID:   r.ID,
			ObjectType: ct.EventTypeResource,
		}, r); err != nil {
			tx.Rollback()
			return err
		}
	}
	return tx.Commit()
}
開發者ID:ably-forks,項目名稱:flynn,代碼行數:47,代碼來源:resource.go


注:本文中的github.com/flynn/flynn/controller/types.Resource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。