removed default Apigee Client ID and added placeholder
This commit is contained in:
parent
a72c0c729a
commit
c1710a53c1
2 changed files with 60 additions and 69 deletions
|
@ -72,15 +72,16 @@ func (fe *frontendServer) homeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := templates.ExecuteTemplate(w, "home", map[string]interface{}{
|
if err := templates.ExecuteTemplate(w, "home", map[string]interface{}{
|
||||||
"session_id": sessionID(r),
|
"session_id": sessionID(r),
|
||||||
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
||||||
"apigee_client_id": currentApigeeClientID(r),
|
"apigee_client_id": currentApigeeClientID(r),
|
||||||
"user_currency": currentCurrency(r),
|
"apigee_client_id_placeholder": ApigeeClientIDPlaceholder,
|
||||||
"currencies": currencies,
|
"user_currency": currentCurrency(r),
|
||||||
"products": ps,
|
"currencies": currencies,
|
||||||
"cart_size": len(cart),
|
"products": ps,
|
||||||
"banner_color": os.Getenv("BANNER_COLOR"), // illustrates canary deployments
|
"cart_size": len(cart),
|
||||||
"ad": fe.chooseAd(r.Context(), []string{}, log),
|
"banner_color": os.Getenv("BANNER_COLOR"), // illustrates canary deployments
|
||||||
|
"ad": fe.chooseAd(r.Context(), []string{}, log),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -131,15 +132,16 @@ func (fe *frontendServer) productHandler(w http.ResponseWriter, r *http.Request)
|
||||||
}{p, price}
|
}{p, price}
|
||||||
|
|
||||||
if err := templates.ExecuteTemplate(w, "product", map[string]interface{}{
|
if err := templates.ExecuteTemplate(w, "product", map[string]interface{}{
|
||||||
"session_id": sessionID(r),
|
"session_id": sessionID(r),
|
||||||
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
||||||
"apigee_client_id": currentApigeeClientID(r),
|
"apigee_client_id": currentApigeeClientID(r),
|
||||||
"ad": fe.chooseAd(r.Context(), p.Categories, log),
|
"apigee_client_id_placeholder": ApigeeClientIDPlaceholder,
|
||||||
"user_currency": currentCurrency(r),
|
"ad": fe.chooseAd(r.Context(), p.Categories, log),
|
||||||
"currencies": currencies,
|
"user_currency": currentCurrency(r),
|
||||||
"product": product,
|
"currencies": currencies,
|
||||||
"recommendations": recommendations,
|
"product": product,
|
||||||
"cart_size": len(cart),
|
"recommendations": recommendations,
|
||||||
|
"cart_size": len(cart),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -237,17 +239,18 @@ func (fe *frontendServer) viewCartHandler(w http.ResponseWriter, r *http.Request
|
||||||
|
|
||||||
year := time.Now().Year()
|
year := time.Now().Year()
|
||||||
if err := templates.ExecuteTemplate(w, "cart", map[string]interface{}{
|
if err := templates.ExecuteTemplate(w, "cart", map[string]interface{}{
|
||||||
"session_id": sessionID(r),
|
"session_id": sessionID(r),
|
||||||
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
||||||
"apigee_client_id": currentApigeeClientID(r),
|
"apigee_client_id": currentApigeeClientID(r),
|
||||||
"user_currency": currentCurrency(r),
|
"apigee_client_id_placeholder": ApigeeClientIDPlaceholder,
|
||||||
"currencies": currencies,
|
"user_currency": currentCurrency(r),
|
||||||
"recommendations": recommendations,
|
"currencies": currencies,
|
||||||
"cart_size": len(cart),
|
"recommendations": recommendations,
|
||||||
"shipping_cost": shippingCost,
|
"cart_size": len(cart),
|
||||||
"total_cost": totalPrice,
|
"shipping_cost": shippingCost,
|
||||||
"items": items,
|
"total_cost": totalPrice,
|
||||||
"expiration_years": []int{year, year + 1, year + 2, year + 3, year + 4},
|
"items": items,
|
||||||
|
"expiration_years": []int{year, year + 1, year + 2, year + 3, year + 4},
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -302,13 +305,14 @@ func (fe *frontendServer) placeOrderHandler(w http.ResponseWriter, r *http.Reque
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := templates.ExecuteTemplate(w, "order", map[string]interface{}{
|
if err := templates.ExecuteTemplate(w, "order", map[string]interface{}{
|
||||||
"session_id": sessionID(r),
|
"session_id": sessionID(r),
|
||||||
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
||||||
"apigee_client_id": currentApigeeClientID(r),
|
"apigee_client_id": currentApigeeClientID(r),
|
||||||
"user_currency": currentCurrency(r),
|
"apigee_client_id_placeholder": ApigeeClientIDPlaceholder,
|
||||||
"order": order.GetOrder(),
|
"user_currency": currentCurrency(r),
|
||||||
"total_paid": &totalPaid,
|
"order": order.GetOrder(),
|
||||||
"recommendations": recommendations,
|
"total_paid": &totalPaid,
|
||||||
|
"recommendations": recommendations,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -354,27 +358,13 @@ func (fe *frontendServer) viewConfigHandler(w http.ResponseWriter, r *http.Reque
|
||||||
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
log := r.Context().Value(ctxKeyLog{}).(logrus.FieldLogger)
|
||||||
log.Debug("Viewing the configuration")
|
log.Debug("Viewing the configuration")
|
||||||
|
|
||||||
currencies, err := fe.getCurrencies(r.Context())
|
|
||||||
if err != nil {
|
|
||||||
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve currencies"), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cart, err := fe.getCart(r.Context(), sessionID(r))
|
|
||||||
if err != nil {
|
|
||||||
renderHTTPError(log, r, w, errors.Wrap(err, "could not retrieve cart"), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
apigeeClientID := currentApigeeClientID(r)
|
apigeeClientID := currentApigeeClientID(r)
|
||||||
|
|
||||||
if err := templates.ExecuteTemplate(w, "config", map[string]interface{}{
|
if err := templates.ExecuteTemplate(w, "config", map[string]interface{}{
|
||||||
"session_id": sessionID(r),
|
"session_id": sessionID(r),
|
||||||
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
||||||
"apigee_client_id": apigeeClientID,
|
"apigee_client_id": apigeeClientID,
|
||||||
"user_currency": currentCurrency(r),
|
"apigee_client_id_placeholder": ApigeeClientIDPlaceholder,
|
||||||
"currencies": currencies,
|
|
||||||
"cart_size": len(cart),
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -420,12 +410,13 @@ func renderHTTPError(log logrus.FieldLogger, r *http.Request, w http.ResponseWri
|
||||||
|
|
||||||
w.WriteHeader(code)
|
w.WriteHeader(code)
|
||||||
templates.ExecuteTemplate(w, "error", map[string]interface{}{
|
templates.ExecuteTemplate(w, "error", map[string]interface{}{
|
||||||
"session_id": sessionID(r),
|
"session_id": sessionID(r),
|
||||||
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
"request_id": r.Context().Value(ctxKeyRequestID{}),
|
||||||
"apigee_client_id": currentApigeeClientID(r),
|
"apigee_client_id": currentApigeeClientID(r),
|
||||||
"error": errMsg,
|
"apigee_client_id_placeholder": ApigeeClientIDPlaceholder,
|
||||||
"status_code": code,
|
"error": errMsg,
|
||||||
"status": http.StatusText(code)})
|
"status_code": code,
|
||||||
|
"status": http.StatusText(code)})
|
||||||
}
|
}
|
||||||
|
|
||||||
func currentCurrency(r *http.Request) string {
|
func currentCurrency(r *http.Request) string {
|
||||||
|
@ -441,7 +432,7 @@ func currentApigeeClientID(r *http.Request) string {
|
||||||
if c != nil {
|
if c != nil {
|
||||||
return c.Value
|
return c.Value
|
||||||
}
|
}
|
||||||
return defaultApigeeClientID
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func sessionID(r *http.Request) string {
|
func sessionID(r *http.Request) string {
|
||||||
|
|
|
@ -35,15 +35,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
port = "8080"
|
port = "8080"
|
||||||
defaultCurrency = "USD"
|
defaultCurrency = "USD"
|
||||||
cookieMaxAge = 60 * 60 * 48
|
cookieMaxAge = 60 * 60 * 48
|
||||||
defaultApigeeClientID = "Add your Apigee Application Client ID here"
|
|
||||||
|
|
||||||
cookiePrefix = "shop_"
|
cookiePrefix = "shop_"
|
||||||
cookieSessionID = cookiePrefix + "session-id"
|
cookieSessionID = cookiePrefix + "session-id"
|
||||||
cookieCurrency = cookiePrefix + "currency"
|
cookieCurrency = cookiePrefix + "currency"
|
||||||
apigeeClientIDHeaderName = "x-api-key"
|
apigeeClientIDHeaderName = "x-api-key"
|
||||||
|
ApigeeClientIDPlaceholder = "Add your Apigee Application Client ID here"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue