<commit_before>// Copyright 2015 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

// Sample bookshelf is a fully-featured app demonstrating several Google Cloud APIs, including Datastore, Cloud SQL, Cloud Storage.
// See https://cloud.google.com/go/getting-started/tutorial-app
package main

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"path"
	"strconv"

	"cloud.google.com/go/pubsub"
	"cloud.google.com/go/storage"

	"github.com/gorilla/handlers"
	"github.com/gorilla/mux"
	uuid "github.com/satori/go.uuid"

	"google.golang.org/appengine"

	"github.com/GoogleCloudPlatform/golang-samples/getting-started/bookshelf"
)

var (
	// See template.go
	listTmpl   = parseTemplate("list.html")
	editTmpl   = parseTemplate("edit.html")
	detailTmpl = parseTemplate("detail.html")
)

func main() {
	registerHandlers()
	appengine.Main()
}

func registerHandlers() {
	// Use gorilla/mux for rich routing.
	// See http://www.gorillatoolkit.org/pkg/mux
	r := mux.NewRouter()

	r.Handle("/", http.RedirectHandler("/books", http.StatusFound))

	r.Methods("GET").Path("/books").
		Handler(appHandler(listHandler))
	r.Methods("GET").Path("/books/mine").
		Handler(appHandler(listMineHandler))
	r.Methods("GET").Path("/books/{id:[0-9]+}").
		Handler(appHandler(detailHandler))
	r.Methods("GET").Path("/books/add").
		Handler(appHandler(addFormHandler))
	r.Methods("GET").Path("/books/{id:[0-9]+}/edit").
		Handler(appHandler(editFormHandler))

	r.Methods("POST").Path("/books").
		Handler(appHandler(createHandler))
	r.Methods("POST", "PUT").Path("/books/{id:[0-9]+}").
		Handler(appHandler(updateHandler))
	r.Methods("POST").Path("/books/{id:[0-9]+}:delete").<commit_msg>getting-started: listen on PORT (#713)<commit_after>// Copyright 2015 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

// Sample bookshelf is a fully-featured app demonstrating several Google Cloud APIs, including Datastore, Cloud SQL, Cloud Storage.
// See https://cloud.google.com/go/getting-started/tutorial-app
package main

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"path"
	"strconv"

	"cloud.google.com/go/pubsub"
	"cloud.google.com/go/storage"

	"github.com/gorilla/handlers"
	"github.com/gorilla/mux"
	uuid "github.com/satori/go.uuid"

	"github.com/GoogleCloudPlatform/golang-samples/getting-started/bookshelf"
)

var (
	// See template.go
	listTmpl   = parseTemplate("list.html")
	editTmpl   = parseTemplate("edit.html")
	detailTmpl = parseTemplate("detail.html")
)

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	registerHandlers()
	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
}

func registerHandlers() {
	// Use gorilla/mux for rich routing.
	// See http://www.gorillatoolkit.org/pkg/mux
	r := mux.NewRouter()

	r.Handle("/", http.RedirectHandler("/books", http.StatusFound))

	r.Methods("GET").Path("/books").
		Handler(appHandler(listHandler))
	r.Methods("GET").Path("/books/mine").
		Handler(appHandler(listMineHandler))
	r.Methods("GET").Path("/books/{id:[0-9]+}").
		Handler(appHandler(detailHandler))
	r.Methods("GET").Path("/books/add").
		Handler(appHandler(addFormHandler))
	r.Methods("GET").Path("/books/{id:[0-9]+}/edit").
		Handler(appHandler(editFormHandler))

	r.Methods("POST").Path("/books").
		Handler(appHandler(createHandler))
	r.Methods("POST", "PUT").Path("/books/{id:[0-9]+}").
		Handler(appHandler(updateHandler))
	r.Methods("POST").Path("/books/{id:[0-9]+}:delete").
{'fraction_non_alphanumeric': 0.18676830928396407, 'fraction_numerical': 0.00952899537163082, 'mean_word_length': 4.617737003058104, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4369104', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1274, 'n_words': 232}