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


Golang wrapper.Wrapper類代碼示例

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


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

示例1: ContentEditorSubmit

// Controller to handle content editor submission.
func ContentEditorSubmit(w *wrapper.Wrapper) {
	elementid := w.APIParams[0]
	e, err := elements.LoadContentElement(elementid, w)
	post := make(map[string]interface{})
	err = form.GetValidFormData(w, &post)
	if err != nil {
		return
	}
	e.ContentValues.Content = post
	delete(e.ContentValues.Content, "mongolartype")
	delete(e.ContentValues.Content, "mongolarid")
	delete(e.ContentValues.Content, "form_id")
	err = e.Save(w)
	if err != nil {
		errmessage := fmt.Sprintf("Element not saved %s by %s", w.APIParams[0], w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to save element.", "Error", w)
		w.Serve()
		return
	}
	services.AddMessage("Element content saved.", "Success", w)
	dynamic := services.Dynamic{
		Target:     elementid,
		Id:         elementid,
		Controller: "admin/element",
		Template:   "admin/element.html",
	}
	services.SetDynamic(dynamic, w)
	w.Serve()
	return

}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:33,代碼來源:content.go

示例2: SlugUrlEditorForm

func SlugUrlEditorForm(w *wrapper.Wrapper) {
	slugid := w.APIParams[0]
	e, err := elements.LoadSlugElement(slugid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Element not found to edit for %s by %s", slugid, w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to load slug parent", "Error", w)
		w.Serve()
		return
	}
	f := form.NewForm()
	data := make(map[string]string)
	for slug, id := range e.Slugs {
		data[id] = slug
		e := elements.NewElement()
		err = elements.GetById(id, &e, w)
		if err != nil {
			errmessage := fmt.Sprintf("Content not found %s : %s", id, err.Error())
			w.SiteConfig.Logger.Error(errmessage)
			services.AddMessage("There was a problem loading some slug elements.", "Error", w)
			w.Serve()
			return
		}
		f.AddText(id, "text").AddLabel(e.Title).Required()

	}
	f.FormData = data
	f.Register(w)
	w.SetTemplate("admin/form.html")
	w.SetPayload("form", f)
	w.Serve()
	return
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:33,代碼來源:slug.go

示例3: ContentTypeEditorSubmit

// Controller to handle submission for content type change form.
func ContentTypeEditorSubmit(w *wrapper.Wrapper) {
	elementid := w.APIParams[0]
	e, err := elements.LoadContentElement(elementid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Element not found to edit for %s by %s", elementid, w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("This element was not found", "Error", w)
		w.Serve()
		return
	}
	type Post struct {
		Type string `json:"type"`
	}
	var post Post
	err = form.GetValidFormData(w, &post)
	if err != nil {
		return
	}
	e.ContentValues.Type = post.Type
	err = e.Save(w)
	if err != nil {
		errmessage := fmt.Sprintf("Element not saved %s by %s", w.APIParams[0], w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to save element.", "Error", w)
	} else {
		services.AddMessage("Element content type saved.", "Success", w)
	}
	w.Serve()
	return
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:31,代碼來源:content.go

示例4: DeleteElement

// Controller to delete an element and all references to the element
func DeleteElement(w *wrapper.Wrapper) {
	id := w.APIParams[0]
	err := elements.Delete(id, w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to delete %s : %s", id, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to delete element.", "Error", w)
	}
	err = elements.WrapperDeleteAllChild(id, w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to delete reference to element %s : %s", id, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to delete all references to your element.", "Error", w)
	}
	err = elements.SlugDeleteAllChild(id, w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to delete reference to element %s : %s", id, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to delete all references to your element.", "Error", w)
	}
	err = paths.DeleteAllChild(id, w)
	if err != nil {
		errmessage := fmt.Sprintf("Unable to delete reference to %s : %s", id, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Unable to delete all references to your element.", "Error", w)
	}
	dynamic := services.Dynamic{
		Target:   id,
		Template: "default.html",
	}
	services.SetDynamic(dynamic, w)
	services.AddMessage("Successfully deleted element", "Success", w)
	w.Serve()
	return
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:36,代碼來源:delete.go

示例5: SortPathForm

// Controller for path sort form.
func SortPathForm(w *wrapper.Wrapper) {
	var parentid string
	if len(w.APIParams) > 0 {
		parentid = w.APIParams[0]
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	p, err := paths.LoadPath(parentid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Path not found to sort for %s by %s.", parentid, w.Request.Host)
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("This element was not found", "Error", w)
		w.Serve()
		return
	} else {
		if len(p.Elements) > 0 {
			w.SetPayload("elements", p.Elements)
		} else {
			services.AddMessage("This has no elements assigned yet.", "Error", w)
		}
		w.SetTemplate("admin/element_sorter.html")
		w.Serve()
		return
	}
}
開發者ID:ultimatums,項目名稱:mongolar,代碼行數:28,代碼來源:children.go

示例6: WrapperValues

// The controller function for Values found directly in the controller values of the element
func WrapperValues(w *wrapper.Wrapper) {
	var wrapid string
	if len(w.APIParams) > 0 {
		wrapid = w.APIParams[0]
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	e, err := elements.LoadWrapperElement(wrapid, w)
	if err != nil {
		errmessage := fmt.Sprintf("Content not found %s : %s", wrapid, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("There was a problem loading some content on your page.", "Error", w)
		w.Serve()
		return
	}
	var v []elements.Element
	for _, id := range e.Elements {
		e := elements.NewElement()
		err = elements.GetById(id, &e, w)
		if err != nil {
			errmessage := fmt.Sprintf("Content not found %s : %s", id, err.Error())
			w.SiteConfig.Logger.Error(errmessage)
		} else {
			v = append(v, e)
		}
	}
	w.SetDynamicId(e.DynamicId)
	w.SetContent(v)
	w.Serve()
}
開發者ID:ultimatums,項目名稱:mongolar,代碼行數:33,代碼來源:wrapper.go

示例7: Login

func (l *LoginMap) Login(w *wrapper.Wrapper) {
	if controller, ok := l.Controllers[w.APIParams[0]]; ok {
		w.Shift()
		controller(w)
		return
	}
	http.Error(w.Writer, "Forbidden", 403)
	return
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:9,代碼來源:oauthlogin.go

示例8: AdminPaths

// Controller to list all paths
func AdminPaths(w *wrapper.Wrapper) {
	pl, err := paths.PathList(w)
	if err != nil {
		services.AddMessage("There was an error retrieving your site paths", "Error", w)
		errmessage := fmt.Sprintf("Error getting path list: %s", err.Error())
		w.SiteConfig.Logger.Error(errmessage)
	} else {
		w.SetContent(pl)
	}
	w.Serve()
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:12,代碼來源:path.go

示例9: Callback

func (lo *LoginMap) Callback(w *wrapper.Wrapper) {
	oauthlogins := make(map[string]map[string]string)
	w.SiteConfig.RawConfig.MarshalKey("OAuthLogins", &oauthlogins)
	loginurls := make(map[string]string)
	w.SiteConfig.RawConfig.MarshalKey("LoginURLs", &loginurls)
	if _, ok := oauthlogins[w.APIParams[0]]; ok {
		if _, ok := lo.Logins[w.APIParams[0]]; ok {
			s := w.Request.FormValue("state")
			sc := oauthlogins[w.APIParams[0]]
			login := lo.Logins[w.APIParams[0]]
			if lo.State != s {
				errmessage := fmt.Sprintf("Invalid oauth state, expected %s, got %s", lo.State, s)
				w.SiteConfig.Logger.Error(errmessage)
				http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
				return
			}
			login.SetConfig(sc, "", "")
			code := w.Request.FormValue("code")
			token, err := login.GetToken(code)
			if err != nil {
				errmessage := fmt.Sprintf("Exchange() failed with %s", err.Error())
				w.SiteConfig.Logger.Error(errmessage)
				http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
				return
			}
			u := login.GetUser()
			err = u.Set(w)
			if err != nil {
				errmessage := fmt.Sprintf("Unable to set user: %s", err.Error())
				w.SiteConfig.Logger.Error(errmessage)
				http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
				return
			}
			err = w.SetSessionValue("user_id", u.MongoId)
			if err != nil {
				errmessage := fmt.Sprintf("Unable to set user id on session: %s", err.Error())
				w.SiteConfig.Logger.Error(errmessage)
				http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
				return
			}
			err = w.SetSessionValue("token", token)
			if err != nil {
				errmessage := fmt.Sprintf("Unable to set token on session: %s", err.Error())
				w.SiteConfig.Logger.Error(errmessage)
				http.Redirect(w.Writer, w.Request, loginurls["failure"], 301)
				return
			}
			http.Redirect(w.Writer, w.Request, loginurls["success"], 301)
			return
		}
	}
	http.Error(w.Writer, "Forbidden", 403)
	return
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:54,代碼來源:oauthlogin.go

示例10: Admin

//Main controller for all admin functions
func (a AdminMap) Admin(w *wrapper.Wrapper) {
	if c, ok := a[w.APIParams[0]]; ok {
		if validateAdmin(w) {
			w.Shift()
			c(w)
		}
		return
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		return
	}
}
開發者ID:ultimatums,項目名稱:mongolar,代碼行數:13,代碼來源:admin.go

示例11: EditContentType

func EditContentType(w *wrapper.Wrapper) {
	if len(w.APIParams) < 1 {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	if w.Request.Method != "POST" {
		EditContentTypeForm(w)
		return
	}
	EditContentTypeSubmit(w)
	return
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:13,代碼來源:contenttype.go

示例12: PathEditor

// Controller for editing paths
func PathEditor(w *wrapper.Wrapper) {
	if len(w.APIParams) == 0 {
		http.Error(w.Writer, "Forbidden", 403)
		w.Serve()
		return
	}
	if w.Request.Method != "POST" {
		PathEditorForm(w)
		return
	}
	PathEditorSubmit(w)
	return
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:14,代碼來源:path.go

示例13: PathEditorForm

// Controller to present path editor form
func PathEditorForm(w *wrapper.Wrapper) {
	pathid := w.APIParams[0]
	f := form.NewForm()
	f.AddText("title", "text").AddLabel("Title").Required()
	f.AddText("path", "text").AddLabel("Path").Required()
	f.AddText("template", "text").AddLabel("Template").Required()
	f.AddCheckBox("wildcard").AddLabel("Wildcard")
	ops := []map[string]string{
		map[string]string{"name": "published", "value": "published"},
		map[string]string{"name": "unpublished", "value": "unpublished"},
	}
	f.AddRadio("status", ops).AddLabel("Status").Required()
	f.AddText("id", "text").Hidden()
	var p paths.Path
	var err error
	if pathid != "new" {
		p, err = paths.LoadPath(pathid, w)
		if err != nil {
			errmessage := fmt.Sprintf("Could not retrieve path %s by %s: %s", w.APIParams[0], w.Request.Host, err.Error())
			w.SiteConfig.Logger.Error(errmessage)
			services.AddMessage("Error retrieving path information.", "Error", w)
			w.Serve()
			return
		}
	} else {
		p = paths.NewPath()
	}
	f.FormData = p
	f.Register(w)
	w.SetTemplate("admin/form.html")
	w.SetPayload("form", f)
	w.Serve()
	return
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:35,代碼來源:path.go

示例14: Admin

//Main controller for all admin functions
func (a AdminMap) Admin(w *wrapper.Wrapper) {
	w.Writer.Header().Add("Cache-Control", "no-cache, no-store, must-revalidate")
	w.Writer.Header().Add("Pragma", "no-cache")
	w.Writer.Header().Add("Expires", "0")
	if c, ok := a[w.APIParams[0]]; ok {
		if validateAdmin(w) {
			w.Shift()
			c(w)
		}
		return
	} else {
		http.Error(w.Writer, "Forbidden", 403)
		return
	}
}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:16,代碼來源:admin.go

示例15: GetValidFormData

func GetValidFormData(w *wrapper.Wrapper, post interface{}) error {
	p := make([]byte, w.Request.ContentLength)
	_, err := w.Request.Body.Read(p)
	if err != nil {
		errmessage := fmt.Sprintf("Error processing post values %s: %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("There was an issue processing your form.", "Error", w)
		w.Serve()
		return errors.New("Could not marshall Post values")
	}
	data := make(map[string]interface{})
	err = json.Unmarshal(p, &data)
	if err != nil {
		errmessage := fmt.Sprintf("Error processing post values %s: %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("There was an issue processing your form.", "Error", w)
		w.Serve()
		return errors.New("Could not marshall Post values")
	}
	register, reg_err := GetFormRegister(data["form_id"].(string), w)
	if reg_err != nil {
		errmessage := fmt.Sprintf("Invalid or expired form %s: %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("Your form was expired, please try again.", "Error", w)
		w.Serve()
		return errors.New("Inalid or expired form")
	}
	err = json.Unmarshal(p, post)
	if err != nil {
		errmessage := fmt.Sprintf("Error processing post values %s: %s", w.Request.Host, err.Error())
		w.SiteConfig.Logger.Error(errmessage)
		services.AddMessage("There was an issue processing your form.", "Error", w)
		w.Serve()
		return errors.New("Could not marshall Post values")
	}
	missing := register.ValidateRequired(data)
	if len(missing) > 0 {
		for _, label := range missing {

			message := fmt.Sprintf("%s is required.", label)
			services.AddMessage(message, "Error", w)
		}
		w.Serve()
		return errors.New("missing fields")
	}
	return nil

}
開發者ID:bdatchar,項目名稱:mongolar,代碼行數:48,代碼來源:formregister.go


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