Golang agoltools.Request类(方法)实例源码

下面列出了Golang agoltools.Request 类(方法)源码代码实例,从而了解它的用法。

作者:keyurv    项目:agoltool   
func getRegisteredApps(r *agoltools.Request) (err error) {
	r.Data["PageTitle"] = "My Registered Apps"

	f := strings.ToLower(strings.Trim(r.R.FormValue("f"), " "))
	if f == "" {
		return r.RenderUsingBaseTemplate(getRegisteredAppsTemplate)
	}

	ris, err := agolclient.GetUserRegisteredApps(r.Transport(), r.Auth)
	if err != nil {
		return err
	}

	if f == "csv" {
		r.W.Header().Set("Content-Type", "text/csv")
		r.W.Header().Set("Content-Disposition", "inline;filename=registeredapps.csv")
		agolclient.RegisteredAppItemsCsv(r.W, ris, r.PortalHomeUrl())
		return
	}

	r.AddData(map[string]interface{}{
		"RegisteredAppItems": ris,
	})

	return r.RenderUsingBaseTemplate(registeredAppsTemplate)
}

作者:keyurv    项目:agoltool   
func callback(r *agoltools.Request) (err error) {
	r.AddData(map[string]interface{}{
		"PageTitle":      "Sign in to ArcGIS Online",
		"AuthCookieName": agoltools.AuthCookie,
	})

	return r.RenderUsingBaseTemplate(callbackTemplate)
}

作者:keyurv    项目:agoltool   
func signIn(r *agoltools.Request) (err error) {
	authUrl := portalAuthorizeUrl

	if redirect := r.R.FormValue("redirect"); strings.HasPrefix(redirect, "/") {
		redirect = url.QueryEscape(redirect)
		authUrl += "&state=" + redirect
	}

	r.Redirect(authUrl)

	return nil
}

作者:keyurv    项目:agoltool   
func getMyAGOL(r *agoltools.Request) (err error) {
	r.Data["PageTitle"] = "Get My ArcGIS Online Information"

	f := strings.ToLower(strings.Trim(r.R.FormValue("f"), " "))
	if f == "" {
		return r.RenderUsingBaseTemplate(getOrgUsersTemplate)
	}

	myagol, err := agolclient.GetMyAGOL(r.Transport(), r.Auth)
	if err != nil {
		return err
	}

	r.Data["PageTitle"] = "My ArcGIS Online Information"

	r.Data["MyAGOL"] = myagol

	orgUrlKey := ""
	if myagol.Org != nil {
		orgUrlKey = myagol.Org.UrlKey
	}
	r.Data["PortalHomeUrl"] = config.PortalHomeUrl(orgUrlKey)

	// panel dropdown and ids
	pdropdown := []string{}
	pids := map[string]string{} //[display name]id

	addPanel := func(condition bool, name, id string) {
		if condition {
			pdropdown = append(pdropdown, name)
			pids[name] = id
		}
	}

	addPanel(myagol.User != nil, "User Info", "user-panel")
	addPanel(myagol.Folders != nil, "My Content", "content-panel")
	addPanel(myagol.User != nil && myagol.User.Groups != nil, "My Groups", "groups-panel")
	addPanel(myagol.Org != nil, "Organization Info", "org-panel")
	addPanel(myagol.Subscription != nil, "Subscription Info", "sub-panel")

	if len(pdropdown) > 1 {
		r.Data["PanelDropdown"] = pdropdown
		r.Data["PanelIds"] = pids
	}

	return r.RenderUsingBaseTemplate(orgUsersTemplate)
}

作者:keyurv    项目:agoltool   
func addFolderServices(r *agoltools.Request) (err error) {
	r.Data["PageTitle"] = "Add Folder Services"

	folderUrl := strings.Trim(r.R.FormValue("folderUrl"), " ")
	if folderUrl == "" {
		return r.RenderUsingBaseTemplate(addFolderServicesTemplate)
	}

	folder, catalog, status, err := agolclient.AddFolderServices(r.Transport(), folderUrl, r.Auth)
	if err != nil {
		return err
	}

	r.Data["Folder"] = folder
	r.Data["Catalog"] = catalog
	r.Data["Status"] = status

	return r.RenderUsingBaseTemplate(folderServicesTemplate)
}

作者:keyurv    项目:agoltool   
func getOrgUsers(r *agoltools.Request) (err error) {
	r.Data["PageTitle"] = "Get Organization Users"

	f := strings.ToLower(strings.Trim(r.R.FormValue("f"), " "))
	if f == "" {
		return r.RenderUsingBaseTemplate(getOrgUsersTemplate)
	}

	us, err := agolclient.GetAllOrgUsers(r.Transport(), r.Auth)
	if err != nil {
		return err
	}

	if f == "csv" {
		r.W.Header().Set("Content-Type", "text/csv")
		r.W.Header().Set("Content-Disposition", "inline;filename=orgusers.csv")
		agolclient.UsersCsv(r.W, us)
		return
	}

	r.Data["Users"] = us

	return r.RenderUsingBaseTemplate(orgUsersTemplate)
}

作者:keyurv    项目:agoltool   
func root(r *agoltools.Request) (err error) {
	r.Data["PageTitle"] = "ArcGIS Online Tools"
	return r.RenderUsingBaseTemplate(rootTemplate)
}

作者:keyurv    项目:agoltool   
func signOut(r *agoltools.Request) (err error) {
	r.SignOut()
	r.Redirect("/")
	return nil
}

作者:keyurv    项目:agoltool   
func getWebMapUrls(r *agoltools.Request) (err error) {
	r.Data["PageTitle"] = "Find Web Maps With URL"

	url := strings.ToLower(strings.Trim(r.R.FormValue("url"), " "))
	if url == "" {
		return r.RenderUsingBaseTemplate(getWebMapUrlsTemplate)
	}

	findFor := strings.ToLower(strings.Trim(r.R.FormValue("for"), " "))

	var wmis []*agolclient.WebMapItem

	if findFor == "org" {
		accountId := r.OrgId()
		if accountId == "" {
			return &agoltools.Error{
				Message: "This option is only available to users that belong to an organization",
				Code:    http.StatusBadRequest,
			}
		}

		wmis, err = agolclient.GetOrgWebMapsWithUrl(r.Transport(), accountId, url, r.Auth)
		if err != nil {
			return err
		}
	} else {
		wmis, err = agolclient.GetUserWebMapsWithUrl(r.Transport(), url, r.Auth)
		if err != nil {
			return err
		}
	}

	f := strings.ToLower(strings.Trim(r.R.FormValue("f"), " "))
	if f == "csv" {
		r.W.Header().Set("Content-Type", "text/csv")
		r.W.Header().Set("Content-Disposition", "inline;filename=webmaps.csv")
		agolclient.WebMapItemsCsv(r.W, wmis, r.PortalHomeUrl())
		return
	}

	r.AddData(map[string]interface{}{
		"PageTitle":   "Web Maps With URL",
		"WebMapItems": wmis,
		"URL":         strings.Trim(r.R.FormValue("url"), " "),
		"For":         findFor,
	})

	return r.RenderUsingBaseTemplate(webMapUrlsTemplate)
}


问题


面经


文章

微信
公众号

扫码关注公众号