本文整理匯總了Golang中igps/page.Params類的典型用法代碼示例。如果您正苦於以下問題:Golang Params類的具體用法?Golang Params怎麽用?Golang Params使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Params類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: checkDeviceID
// checkDeviceID checks the specified device ID and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid).
func checkDeviceID(p *page.Params, devIDst string, isCar bool, devices []*ds.Device) (ok bool) {
var fieldName string
if isCar {
fieldName = `<span class="code">Car GPS Device</span>`
} else {
fieldName = `<span class="code">Personal Mobile GPS Device</span>`
}
if devIDst == "" {
if !isCar {
// Personal Mobile device is optional
return true
}
p.ErrorMsg = template.HTML(fieldName + " must be provided! Please select a Device from the list.")
return false
}
var devID int64
var err error
if devID, err = strconv.ParseInt(devIDst, 10, 64); err != nil {
p.ErrorMsg = template.HTML("Invalid " + fieldName + "! Please select a Device from the list.")
return false
}
// Check if device is owned by the user:
for _, d := range devices {
if d.KeyID == devID {
return true
}
}
p.ErrorMsg = "You do not have access to the specified Device! Please select a Device from the list."
return false
}
示例2: checkMapPrevSize
// checkMapPrevSize checks the specified Map preview size string and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid or empty).
func checkMapPrevSize(p *page.Params, settingName, mps string) (ok bool) {
if mps == "" {
return true
}
basemsg := `Invalid <span class="code">` + settingName + `</span>!`
parts := strings.Split(mps, "x")
if len(parts) != 2 {
p.ErrorMsg = template.HTML(basemsg)
return false
}
for i, part := range parts {
name := []string{"width", "height"}[i]
num, err := strconv.Atoi(part)
if err != nil {
p.ErrorMsg = SExecTempl(basemsg+` Invalid number for {{index . 0}}: <span class="highlight">{{index . 1}}</span>`, []interface{}{name, part})
return false
}
if num < 100 || num > 640 { // 640 is an API limit for free accounts
p.ErrorMsg = SExecTempl(basemsg+` {{index . 0}} is outside of valid range (100..640): <span class="highlight">{{index . 1}}</span>`, []interface{}{name, part})
return false
}
}
return true
}
示例3: checkName
// checkName checks the specified Device name and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid).
func checkName(p *page.Params, name string) (ok bool) {
switch {
case len(name) == 0:
p.ErrorMsg = template.HTML(`<span class="code">Name</span> must be specified!`)
return false
case len(name) > 500:
p.ErrorMsg = template.HTML(`<span class="code">Name</span> is too long! (cannot be longer than 500 characters)`)
return false
}
return true
}
示例4: checkLogsRetention
// checkLogsRetention checks the specified logs retention and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid).
func checkLogsRetention(p *page.Params, logsRetention string) (ok bool) {
basemsg := `Invalid <span class="code">Logs Retention</span>!`
num, err := strconv.Atoi(logsRetention)
if err != nil {
p.ErrorMsg = template.HTML(basemsg)
return false
}
if num < 0 || num > 9999 {
p.ErrorMsg = SExecTempl(basemsg+` Value is outside of valid range (0..9,999): <span class="highlight">{{.}}</span>`, num)
return false
}
return true
}
示例5: checkContactEmail
// checkContactEmail checks the specified Contact Email and sets an appropriate erorr message
// if there's something wrong with it.
// Returns true if email is acceptable (valid or empty).
func checkContactEmail(p *page.Params, email string) (ok bool) {
if email == "" {
return true
}
if len(email) > 500 {
p.ErrorMsg = template.HTML(`<span class="code">Contact email</span> is too long! (cannot be longer than 500 characters)`)
return false
}
if _, err := mail.ParseAddressList(email); err != nil {
p.ErrorMsg = template.HTML(`Invalid <span class="code">Contact email</span>!`)
return false
}
return true
}
示例6: checkAcceptTermsAndPolicy
// checkAcceptTermsAndPolicy checks the specified accept terms and policty response and sets an appropriate erorr message
// if there's something wrong with it.
// Returns true if it is acceptable (checked).
func checkAcceptTermsAndPolicy(p *page.Params, atap string) (ok bool) {
if atap == "" {
p.ErrorMsg = "You must accept the Terms and Policy!"
return false
}
return true
}
示例7: checkSearchPrecision
// checkSearchPrecision checks the specified search precision and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid).
func checkSearchPrecision(p *page.Params, searchPrecision string) (ok bool) {
basemsg := `Invalid <span class="code">Search Precision</span>!`
num, err := strconv.ParseInt(searchPrecision, 10, 64)
if err != nil {
p.ErrorMsg = template.HTML(basemsg)
return false
}
if num < 0 || num > 1000*1000 {
p.ErrorMsg = SExecTempl(basemsg+` Value is outside of valid range (0..1,000,000): <span class="highlight">{{.}}</span>`, num)
return false
}
if num%100 != 0 {
p.ErrorMsg = SExecTempl(basemsg+` Value is not a multiple of 100: <span class="highlight">{{.}}</span>`, num)
return false
}
return true
}
示例8: checkMobPageWidth
// checkMobPageWidth checks the specified Mobile Page width string and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid or empty).
func checkMobPageWidth(p *page.Params, mpw string) (ok bool) {
if mpw == "" {
return true
}
basemsg := `Invalid <span class="code">Mobile Page width</span>!`
num, err := strconv.Atoi(mpw)
if err != nil {
p.ErrorMsg = SExecTempl(basemsg+` Invalid number: <span class="highlight">{{.}}</span>`, mpw)
return false
}
if num < 400 || num > 10000 {
p.ErrorMsg = SExecTempl(basemsg+` Value is outside of valid range (400..10000): <span class="highlight">{{.}}</span>`, num)
return false
}
return true
}
示例9: checkLogsPageSize
// checkLogsPageSize checks the specified Logs Page Size string and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid or empty).
func checkLogsPageSize(p *page.Params, lps string) (ok bool) {
if lps == "" {
return true
}
basemsg := `Invalid <span class="code">Logs Table Page Size</span>!`
num, err := strconv.Atoi(lps)
if err != nil {
p.ErrorMsg = SExecTempl(basemsg+` Invalid number: <span class="highlight">{{.}}</span>`, lps)
return false
}
if num < 5 || num > 30 {
p.ErrorMsg = SExecTempl(basemsg+` Value is outside of valid range (5..30): <span class="highlight">{{.}}</span>`, num)
return false
}
return true
}
示例10: checkGoogleAccounts
// checkGoogleAccounts checks if previous and current Google Accounts match and sets an error message
// informing the user that the currently logged in Google Account has changed.
// Returns true if Google Accounts match.
func checkGoogleAccounts(p *page.Params, googleAccount string) (ok bool) {
if googleAccount == p.User.Email {
return true
}
const msg = `The current logged in user <span class="highlight">{{.User}}</span> does not match the <span class="code">Google Account</span>.<br/>
This is most likely due to you switched Google Accounts.<br/>
Click here to reload the {{.Page.Link}} page.`
p.ErrorMsg = SExecTempl(msg, p)
return false
}
示例11: checkLocationName
// checkLocationName checks the specified Location name and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid or empty).
func checkLocationName(p *page.Params, locnam string) (ok bool) {
if locnam == "" {
return true
}
_, err := time.LoadLocation(locnam)
if err != nil {
p.ErrorMsg = template.HTML(`Invalid <span class="code">Location name</span>!`)
return false
}
return true
}
示例12: checkMobMapImgFormat
// checkMobMapImgFormat checks the specified Mobile Map image format and sets an appropriate error message
// if there's something wrong with it.
// Returns true if is acceptable (valid or empty).
func checkMobMapImgFormat(p *page.Params, imgFormat string) (ok bool) {
if imgFormat == "" {
return true
}
for _, v := range imgFormats {
if v == imgFormat {
return true
}
}
p.ErrorMsg = template.HTML(`Invalid <span class="code">Mobile Map image format</span>!`)
return false
}
示例13: genNewRandID
// genNewID generates a new, unique device ID
func genNewRandID(p *page.Params, d *ds.Device) {
b := make([]byte, 9) // Use 9 bytes: multiple of 3 bytes (ideal for base64 encoding so no padding '=' signs will be needed)
if _, p.Err = rand.Read(b); p.Err != nil {
return
}
RandID := base64.URLEncoding.EncodeToString(b)
// Check if RandID is unique.
// It will be, but once in a million years we might maybe perhaps encounter a match!
q := datastore.NewQuery(ds.ENameDevice).Filter(ds.PNameRandID+"=", RandID).KeysOnly().Limit(1)
var devKeys []*datastore.Key
if devKeys, p.Err = q.GetAll(p.AppCtx, nil); p.Err != nil {
return
}
if len(devKeys) > 0 {
p.Err = fmt.Errorf("Generated device RandID already exists: %s", RandID)
return
}
d.RandID = RandID
}
示例14: logs
// logs is the logic implementation of the Logs page.
func logs(p *page.Params) {
c := p.AppCtx
// First get devices
var devices []*ds.Device
if devices, p.Err = cache.GetDevListForAccKey(c, p.Account.GetKey(c)); p.Err != nil {
return
}
p.Custom["Devices"] = devices
fv := p.Request.FormValue
p.Custom["Before"] = fv("before")
p.Custom["After"] = fv("after")
p.Custom["SearchLoc"] = fv("loc")
if fv("devID") == "" {
// No device chosen yet
return
}
var err error
var devID int64
if devID, err = strconv.ParseInt(string(fv("devID")), 10, 64); err != nil {
p.ErrorMsg = "Invalid Device! Please select a Device from the list below."
return
}
// Check if device is owned by the user:
var dev *ds.Device
for _, d := range devices {
if d.KeyID == devID {
dev = d
p.Custom["Device"] = d
break
}
}
if dev == nil {
p.ErrorMsg = "You do not have access to the specified Device! Please select a Device from the list below."
return
}
// Parse filters:
var before time.Time
if fv("before") != "" {
if before, err = p.ParseTime(timeLayout, strings.TrimSpace(fv("before"))); err != nil {
p.ErrorMsg = template.HTML(`Invalid <span class="highlight">Before</span>!`)
return
}
// Add 1 second to the parsed time because fraction of a second is not parsed but exists,
// so this new time will also include records which has the same time up to the second part and has millisecond part too.
before = before.Add(time.Second)
}
var after time.Time
if fv("after") != "" {
if after, err = p.ParseTime(timeLayout, strings.TrimSpace(fv("after"))); err != nil {
p.ErrorMsg = template.HTML(`Invalid <span class="highlight">After</span>!`)
return
}
}
var searchLoc appengine.GeoPoint
areaCode := int64(-1)
if dev.Indexed() && fv("loc") != "" {
// GPS coordinates; lat must be in range -90..90, lng must be in range -180..180
baseErr := template.HTML(`Invalid <span class="highlight">Location</span>!`)
var coords = strings.Split(strings.TrimSpace(fv("loc")), ",")
if len(coords) != 2 {
p.ErrorMsg = baseErr
return
}
searchLoc.Lat, err = strconv.ParseFloat(coords[0], 64)
if err != nil {
p.ErrorMsg = baseErr
return
}
searchLoc.Lng, err = strconv.ParseFloat(coords[1], 64)
if err != nil {
p.ErrorMsg = baseErr
return
}
if !searchLoc.Valid() {
p.ErrorMsg = template.HTML(`Invalid <span class="highlight">Location</span> specified by latitude and longitude! Valid range: [-90, 90] latitude and [-180, 180] longitude`)
return
}
areaCode = AreaCodeForGeoPt(dev.AreaSize, searchLoc.Lat, searchLoc.Lng)
}
var page int
cursorsString := fv("cursors")
var cursors = strings.Split(cursorsString, ";")[1:] // Split always returns at least 1 element (and we use semicolon separator before cursors)
// Form values
if fv("page") == "" {
page = 1
} else {
page, err = strconv.Atoi(fv("page"))
if err != nil || page < 1 {
//.........這裏部分代碼省略.........
示例15: settings
// settings is the logic implementation of the Settings page.
func settings(p *page.Params) {
p.Custom["ImgFormats"] = imgFormats
fv := p.Request.PostFormValue
if fv("submitSettings") == "" {
// No form submitted. Initial values:
p.Custom["GoogleAccount"] = p.Account.Email
p.Custom["ContactEmail"] = p.Account.ContactEmail
p.Custom["LocationName"] = p.Account.LocationName
if p.Account.LogsPageSize > 0 {
p.Custom["LogsPageSize"] = p.Account.LogsPageSize
}
p.Custom["MapPrevSize"] = p.Account.MapPrevSize
p.Custom["MobMapPrevSize"] = p.Account.MobMapPrevSize
p.Custom["MobMapImgFormat"] = p.Account.MobMapImgFormat
if p.Account.MobPageWidth > 0 {
p.Custom["MobPageWidth"] = p.Account.MobPageWidth
}
return
}
p.Custom["GoogleAccount"] = fv("googleAccount")
p.Custom["ContactEmail"] = fv("contactEmail")
p.Custom["LocationName"] = fv("locationName")
p.Custom["LogsPageSize"] = fv("logsPageSize")
p.Custom["MapPrevSize"] = fv("mapPrevSize")
p.Custom["MobMapPrevSize"] = fv("mobMapPrevSize")
p.Custom["MobMapImgFormat"] = fv("mobMapImgFormat")
p.Custom["MobPageWidth"] = fv("mobPageWidth")
// Checks:
switch {
case !checkGoogleAccounts(p, fv("googleAccount")):
case !checkContactEmail(p, fv("contactEmail")):
case !checkLocationName(p, fv("locationName")):
case !checkLogsPageSize(p, fv("logsPageSize")):
case !checkMapPrevSize(p, "Map preview size", fv("mapPrevSize")):
case !checkMapPrevSize(p, "Mobile Map preview size", fv("mobMapPrevSize")):
case !checkMobMapImgFormat(p, fv("mobMapImgFormat")):
case !checkMobPageWidth(p, fv("mobPageWidth")):
}
if p.ErrorMsg != nil {
return
}
// All data OK, save Account
c := p.AppCtx
// Create a "copy" of the account, only set it if saving succeeds.
// Have to set ALL fields (else their values would be lost when (re)saved)!
var logsPageSize, mobPageWidth int
if fv("logsPageSize") != "" {
logsPageSize, _ = strconv.Atoi(fv("logsPageSize"))
}
if fv("mobPageWidth") != "" {
mobPageWidth, _ = strconv.Atoi(fv("mobPageWidth"))
}
acc := ds.Account{
Email: p.User.Email, Lemail: strings.ToLower(p.User.Email), UserID: p.User.ID,
ContactEmail: fv("contactEmail"), LocationName: fv("locationName"), LogsPageSize: logsPageSize,
MapPrevSize: fv("mapPrevSize"), MobMapPrevSize: fv("mobMapPrevSize"),
MobMapImgFormat: fv("mobMapImgFormat"), MobPageWidth: mobPageWidth,
Created: p.Account.Created, KeyID: p.Account.KeyID,
}
key := datastore.NewKey(c, ds.ENameAccount, "", p.Account.KeyID, nil)
if _, p.Err = datastore.Put(c, key, &acc); p.Err == nil {
p.InfoMsg = "Settings saved successfully."
p.Account = &acc
// Update cache with the new Account
cache.CacheAccount(c, p.Account)
}
}