backend

package
v0.0.0-...-9217bb4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2019 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Provide a simple JSON response with a customizable delay

Index

Constants

View Source
const (
	AMP_ACCESS_SAMPLE_PATH = "/" + CATEGORY_COMPONENTS + "/amp-access/"
	AMP_ACCESS_COOKIE      = "ABE_LOGGED_IN"
)
View Source
const (
	ERROR_CASE_AMP_FORM = "error"
	SAMPLE_NAME         = "/" + CATEGORY_COMPONENTS + "/amp-form/"
)
View Source
const (
	AMP_LIVE_LIST_COOKIE_NAME      = "ABE_AMP_LIVE_LIST_STATUS"
	FIFTEEN_SECONDS                = 15
	MAX_BLOG_ITEMS_NUMBER_PER_PAGE = 5
	BLOG_ID_PREFIX                 = "post"
)
View Source
const (
	COMMENT_SAMPLE_PATH = "/" + CATEGORY_SAMPLE_TEMPLATES + "/comment_section/"
	USER                = "Mark"
)
View Source
const (
	DIST_FOLDER     = "dist"
	TEMPLATE_FOLDER = "templates"

	AMP_CLIENT_ID_COOKIE = "AMP_ECID_GOOGLE"

	CATEGORY_ADVANCED         = "advanced"
	CATEGORY_COMPONENTS       = "components"
	CATEGORY_SAMPLE_TEMPLATES = "samples_templates"
	// Where to find the SXG service (i.e. host running https://github.com/ampproject/amppackager)
	PACKAGER_PREFIX = "https://amp-by-example-sxg.appspot.com/"
)
View Source
const (
	ECHO_ENDPOINT = "/echo"

	MAX_FORM_SIZE = 1024 * 100
)
View Source
const (
	AMP_FAVORITE_COOKIE       = "amp-favorite"
	AMP_FAVORITE_COUNT_COOKIE = "amp-favorite-with-count"
)
View Source
const (
	ERROR_CASE_HOUSING  = "error"
	HOUSING_SAMPLE_PATH = "/" + CATEGORY_SAMPLE_TEMPLATES + "/housing/"
)
View Source
const (
	PAGED_LIST_SAMPLE_PATH = "/" + CATEGORY_ADVANCED + "/paged_list/"
	MAX_PAGE_COUNT         = 5
	ITEMS_PER_PAGE         = 4
)
View Source
const (
	ERROR_CASE_POLL       = "error"
	POLL_SAMPLE_PATH      = "/" + CATEGORY_SAMPLE_TEMPLATES + "/poll/"
	POLL_ANSWER           = "PollAnswer"
	ALREADY_VOTED_MESSAGE = "You have already answered this poll. If you want to run this sample again, use an incognito window."
	THANKS_MESSAGE        = "Thanks for answering the poll!"
	POLL_COOKIE_NAME      = "POLL_USER_ID"
)
View Source
const (
	SEARCH           = "search"
	SHOPPING_CART    = "shopping_cart"
	ADD_TO_CART_PATH = "/samples_templates/product_page/add_to_cart"
	ABE_CLIENT_ID    = "ABE_CLIENT_ID"
	SHOW_MORE_PATH   = "/json/more_related_products_page"
)
View Source
const (
	SLOW_JSON_SAMPLE_PATH            = "/" + CATEGORY_SAMPLE_TEMPLATES + "/slow-json/"
	SLOW_JSON_WITH_ITEMS_SAMPLE_PATH = "/" + CATEGORY_SAMPLE_TEMPLATES + "/slow-json-with-items/"
	SLOW_IFRAME_SAMPLE_PATH          = "/" + CATEGORY_SAMPLE_TEMPLATES + "/slow-iframe/"
)
View Source
const (
	MAX_AGE_IN_SECONDS = 180 // three minutes
	OLD_ADDRESS        = "amp-by-example.appspot.com"
	DIST_DIR           = "dist"
)
View Source
const (
	AMP_INPUTMASK_SAMPLE_NAME = "/" + CATEGORY_COMPONENTS + "/amp-inputmask/"
)
View Source
const (
	AUTOSUGGEST_SAMPLE_PATH = "/" + CATEGORY_ADVANCED + "/autosuggest/"
)
View Source
const (
	BIND_SAMPLE_PATH = "/" + CATEGORY_COMPONENTS + "/time/"
)
View Source
const (
	CONSENT_SAMPLE_PATH = "/" + CATEGORY_SAMPLE_TEMPLATES + "/consent/"
)
View Source
const DEFAULT_MAX_AGE = 60
View Source
const (
	EMAIL_BASE_PATH = "/amphtml-email/"
)
View Source
const HOST = "https://ampbyexample.com"
View Source
const (
	HOTEL_SAMPLE_PATH = "/" + CATEGORY_SAMPLE_TEMPLATES + "/hotel/"
)
View Source
const NEW_ADDRESS = "https://ampbyexample.com"
View Source
const NUMBER_OF_CONFIGS = 5
View Source
const (
	OAUTH_BASE = "/oauth/"
)
View Source
const (
	RATING_SAMPLE_PATH = "/" + CATEGORY_SAMPLE_TEMPLATES + "/rating/"
)
View Source
const SHOPPING_CART_TOTAL = 9.94

Variables

View Source
var MODES = [...]string{"", "/embed", "/source", "/preview", "/preview/embed"}

Functions

func CaseInsensitiveContains

func CaseInsensitiveContains(s, substr string) bool

func EnableCors

func EnableCors(next http.HandlerFunc) http.HandlerFunc

func Filter

func Filter(vs []string, f func(string) bool) []string

func GetHost

func GetHost(r *http.Request) string

func GetOrigin

func GetOrigin(r *http.Request) string

func GetSourceOrigin

func GetSourceOrigin(r *http.Request) string

func InitAmpAccess

func InitAmpAccess()

func InitAmpAnalytics

func InitAmpAnalytics()

func InitAmpCache

func InitAmpCache()

func InitAmpConsent

func InitAmpConsent()

func InitAmpEmail

func InitAmpEmail()

func InitAmpForm

func InitAmpForm()

func InitAmpInputmask

func InitAmpInputmask()

func InitAmpLiveList

func InitAmpLiveList()

func InitAmpStoryAutoAds

func InitAmpStoryAutoAds()

func InitAutosuggestSample

func InitAutosuggestSample()

func InitCheckout

func InitCheckout()

func InitCommentSection

func InitCommentSection()

func InitEcho

func InitEcho()

func InitFavoriteSample

func InitFavoriteSample()

func InitHotelSample

func InitHotelSample()

func InitHousingForm

func InitHousingForm()

func InitOAuth

func InitOAuth()

func InitPackager

func InitPackager()

func InitPagedListSample

func InitPagedListSample()

func InitPollSample

func InitPollSample()

func InitProductBrowse

func InitProductBrowse()

func InitRatingSample

func InitRatingSample()

func InitRedirects

func InitRedirects()

func InitSeatmapPage

func InitSeatmapPage()

func InitSlowResponseSample

func InitSlowResponseSample()

func InitStateRefreshSection

func InitStateRefreshSection()

func InitStatic

func InitStatic()

func IsInsecureRequest

func IsInsecureRequest(r *http.Request) bool

func Min

func Min(x, y int) int

func RedirectToSecureVersion

func RedirectToSecureVersion(w http.ResponseWriter, r *http.Request)

func RegisterHandler

func RegisterHandler(pattern string, handler http.HandlerFunc)

func RegisterSample

func RegisterSample(samplePath string, handler func(http.ResponseWriter, *http.Request, Page))

RegisterSample adds routes for different sample modes, e.g. (my_sample/embed, my_sample/preview,..). Use it whenever a sample requires a custom backend logic.

func RegisterSampleEndpoint

func RegisterSampleEndpoint(samplePath string, name string,
	handler func(http.ResponseWriter, *http.Request, Page))

RegisterSampleEndpoint adds routes for different sample modes ((my_sample/search/embed, my_sample/search/preview,..)). Use this for samples requiring additional mode specific endpoints.

func RegisterTemplate

func RegisterTemplate(route string, mode string, templatePath string,
	handler func(http.ResponseWriter, *http.Request, Page))

RegisterTemplate configures a handler for requests rendering a template.

func SendAmpListItems

func SendAmpListItems(w http.ResponseWriter, data ...interface{})

func SendJsonError

func SendJsonError(w http.ResponseWriter, code int, data interface{})

func SendJsonFile

func SendJsonFile(w http.ResponseWriter, filePath string)

func SendJsonResponse

func SendJsonResponse(w http.ResponseWriter, data interface{})

func SetContentTypeJson

func SetContentTypeJson(w http.ResponseWriter)

func SetDefaultMaxAge

func SetDefaultMaxAge(w http.ResponseWriter)

func SetMaxAge

func SetMaxAge(w http.ResponseWriter, age int)

func SetVary

func SetVary(h http.Handler) http.Handler

Types

type AccessData

type AccessData struct {
	ReturnURL string
}

type AmpListResponse

type AmpListResponse struct {
	Items PagedResponse `json:"items"`
}

func GeneratePagedResponse

func GeneratePagedResponse(page int) AmpListResponse

type ArticleBody

type ArticleBody struct {
	Type string `json:"@type"`
}

type Author

type Author struct {
	Type   string `json:"@type"`
	SameAs string `json:"sameAs"`
	Name   string `json:"name"`
}

type AuthorizationResponse

type AuthorizationResponse interface {
	CreateAuthorizationResponse() AuthorizationResponse
}

type BlogItem

type BlogItem struct {
	Text              string
	Image             string
	Timestamp         string
	Date              string
	ID                string
	Heading           string
	MetadataTimestamp string
}

type BlogPosting

type BlogPosting struct {
	Type            string      `json:"@type"`
	Headline        string      `json:"headline"`
	URL             string      `json:"url"`
	DatePublished   string      `json:"datePublished"`
	Author          Author      `json:"author"`
	BlogArticleBody ArticleBody `json:"articleBody"`
	BlogPublisher   Publisher   `json:"publisher"`
	BlogImage       Image       `json:"image"`
}

type ByPriceAsc

type ByPriceAsc []Product

func (ByPriceAsc) Len

func (a ByPriceAsc) Len() int

func (ByPriceAsc) Less

func (a ByPriceAsc) Less(i, j int) bool

func (ByPriceAsc) Swap

func (a ByPriceAsc) Swap(i, j int)

type ByPriceDesc

type ByPriceDesc []Product

func (ByPriceDesc) Len

func (a ByPriceDesc) Len() int

func (ByPriceDesc) Less

func (a ByPriceDesc) Less(i, j int) bool

func (ByPriceDesc) Swap

func (a ByPriceDesc) Swap(i, j int)

type ClientId

type ClientId struct {
	// contains filtered or unexported fields
}

holds a boolean value used for storing the ClientId

type Comment

type Comment struct {
	Text     string
	User     string
	Datetime string
}

type HotelAuthorizationResponse

type HotelAuthorizationResponse struct {
	User       string `json:"username"`
	Status     string `json:"status"`
	Freenights int    `json:"freenights"`
}

func (HotelAuthorizationResponse) CreateAuthorizationResponse

func (h HotelAuthorizationResponse) CreateAuthorizationResponse() AuthorizationResponse

type Image

type Image struct {
	Type   string `json:"@type"`
	URL    string `json:"url"`
	Width  string `json:"width"`
	Height string `json:"height"`
}

type JsonRoot

type JsonRoot struct {
	Products     []Product `json:"items"`
	HasMorePages bool      `json:"hasMorePages"`
}

type Key

type Key interface{}

type LRUCache

type LRUCache struct {
	MaxEntries int
	// contains filtered or unexported fields
}

func NewLRUCache

func NewLRUCache(maxEntries int) *LRUCache

func (*LRUCache) Add

func (c *LRUCache) Add(key Key, value interface{})

func (*LRUCache) Get

func (c *LRUCache) Get(key Key) (value interface{}, ok bool)

func (*LRUCache) Len

func (c *LRUCache) Len() int

func (*LRUCache) Remove

func (c *LRUCache) Remove(key Key)

func (*LRUCache) RemoveOldest

func (c *LRUCache) RemoveOldest()

type LiveBlogSample

type LiveBlogSample struct {
	BlogItems     []BlogItem
	FootballScore Score
	BlogMetadata  template.JS
	NextPageURL   string
	PrevPageURL   string
	PageNumber    int
	Disabled      template.HTMLAttr
}

type MortgageForm

type MortgageForm struct {
	Price    int
	Deposit  int
	Interest float64
	Period   int
}

type Page

type Page struct {
	Mode  string
	Route string
	// contains filtered or unexported fields
}

func (Page) Render

func (self Page) Render(wr io.Writer, data interface{})

type PagedResponse

type PagedResponse struct {
	CurrentPage int              `json:"currentPage"`
	PageCount   int              `json:"pageCount"`
	Products    []ProductListing `json:"products"`
}

type Poll

type Poll struct {
	PollAnswers []int
}

holds stored Poll, PollAnswers is an array where index is the question and the value is the vote count

type PollAnswer

type PollAnswer struct {
	Answer int
	Votes  int
}

holds an answer and votes, used for storing

type PollEntryResult

type PollEntryResult struct {
	Votes      int
	Percentage []int
	Answer     string
}

holds an answers and votes represented as an array, used for displaying

type PollForm

type PollForm struct {
	ClientId string
	Answer   int
}

holds the answer chosen by the user and the client id, used for storing data coming from the UI

type PollQuestions

type PollQuestions struct {
	Questions []string
}

holds the questions

type PollResult

type PollResult struct {
	PollEntryResults []PollEntryResult
	Message          string
}

holds the poll results and a message, used for displaying

type Product

type Product struct {
	Id          int    `json:"id"`
	Img         string `json:"img"`
	Name        string `json:"name"`
	Price       string `json:"price"`
	Stars       string `json:"stars"`
	Attribution string `json:"attribution"`
	Url         string `json:"url"`
	Color       string `json:"color"`
}

func (*Product) StarsAsHtml

func (p *Product) StarsAsHtml() template.HTML

type ProductBrowsePage

type ProductBrowsePage struct {
	Title        string
	Products     []Product
	SearchAction string
	Mode         string
}

type ProductListing

type ProductListing struct {
	Title string `json:"title"`
	Image string `json:"image"`
	Copy  string `json:"copy"`
}

type ProductPage

type ProductPage struct {
	Mode string
}

type Publisher

type Publisher struct {
	Type             string `json:"@type"`
	Name             string `json:"name"`
	BlogPostingImage Image  `json:"logo"`
}

type Redirect

type Redirect struct {
	Source string `json:"source"`
	Target string `json:"target"`
}

type Score

type Score struct {
	Timestamp  string
	ScoreTeam1 int
	ScoreTeam2 int
}

type Seat

type Seat struct {
	Id           string  `json:"id"`
	Standard     bool    `json:"standard"`
	X            float64 `json:"x"`
	Y            float64 `json:"y"`
	Rx           string  `json:"rx"`
	Ry           string  `json:"ry"`
	Height       float64 `json:"height"`
	Width        float64 `json:"width"`
	Wheelchair   bool    `json:"wheelchair"`
	Availability bool    `json:"availability"`
}

type SeatJsonRoot

type SeatJsonRoot struct {
	Seats  []Seat  `json:"seats"`
	Height float64 `json:"height"`
	Width  float64 `json:"width"`
}

type ShoppingCartItem

type ShoppingCartItem struct {
	Name  string `json:"name"`
	Price string `json:"price"`
	Color string `json:"color"`
	Size  string `json:"size"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL