-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0bb8dfd
Showing
4 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# How to Contribute | ||
|
||
We'd love to accept your patches and contributions to this project. There are | ||
just a few small guidelines you need to follow. | ||
|
||
## Contributor License Agreement | ||
|
||
Contributions to this project must be accompanied by a Contributor License | ||
Agreement. You (or your employer) retain the copyright to your contribution, | ||
this simply gives us permission to use and redistribute your contributions as | ||
part of the project. Head over to <https://cla.developers.google.com/> to see | ||
your current agreements on file or to sign a new one. | ||
|
||
You generally only need to submit a CLA once, so if you've already submitted one | ||
(even if it was for a different project), you probably don't need to do it | ||
again. | ||
|
||
## Code reviews | ||
|
||
All submissions, including submissions by project members, require review. We | ||
use GitHub pull requests for this purpose. Consult | ||
[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more | ||
information on using pull requests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Go Vanity URLs | ||
|
||
Go Vanity URLs is a simple App Engine Go app that allows you | ||
to set custom import paths for your Go packages. | ||
|
||
## Quickstart | ||
|
||
Get the application: | ||
``` | ||
go get -u -d github.com/GoogleCloudPlatform/govanityurls | ||
cd $(go env GOPATH)/github.com/GoogleCloudPlatform/govanityurls | ||
``` | ||
|
||
Edit `app.yaml` with your domain and git repo information. | ||
|
||
``` | ||
env_variables: | ||
DOMAIN: go.grpcutil.org | ||
REPO: https://github.com/rakyll/grpcutil | ||
``` | ||
|
||
Deploy the app: | ||
|
||
``` | ||
$ gcloud app deploy | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
runtime: go | ||
api_version: go1 | ||
|
||
handlers: | ||
- url: /.* | ||
script: _go_app | ||
|
||
env_variables: | ||
DOMAIN: portmidigo.org | ||
REPO: https://github.com/rakyll/portmidi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2017 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package main contains an App Engine that serves vanity URLs for a git repo. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strings" | ||
) | ||
|
||
type pkg struct { | ||
Import string | ||
Repo string | ||
Display string | ||
CurrentPkg string | ||
} | ||
|
||
var ( | ||
domain string | ||
repo string | ||
display string | ||
) | ||
|
||
func init() { | ||
mustLoad("DOMAIN", &domain) | ||
mustLoad("REPO", &repo) | ||
if strings.Contains(repo, "github.com") { | ||
display = fmt.Sprintf("%v %v/tree/master{/dir} %v/blob/master{/dir}/{file}#L{line}", repo, repo, repo) | ||
} | ||
if display == "" { | ||
mustLoad("DISPLAY", &display) | ||
} | ||
http.HandleFunc("/", handle) | ||
} | ||
|
||
func handle(w http.ResponseWriter, r *http.Request) { | ||
current := r.URL.Path | ||
if err := vanityTmpl.Execute(w, &pkg{ | ||
Import: domain, | ||
Repo: repo, | ||
Display: display, | ||
CurrentPkg: current, | ||
}); err != nil { | ||
http.Error(w, "cannot render the page", http.StatusInternalServerError) | ||
} | ||
} | ||
|
||
var vanityTmpl, _ = template.New("vanity").Parse(`<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | ||
<meta name="go-import" content="{{.Import}} git {{.Repo}}"> | ||
<meta name="go-source" content="{{.Import}} {{.Display}}"> | ||
<meta http-equiv="refresh" content="0; url=https://godoc.org/{{.Import}}{{.CurrentPkg}}"> | ||
</head> | ||
<body> | ||
Nothing to see here; <a href="https://godoc.org/{{.Import}}{{.CurrentPkg}}">move along</a>. | ||
</body> | ||
</html>`) | ||
|
||
func mustLoad(key string, value *string) { | ||
v := os.Getenv(key) | ||
if v == "" { | ||
log.Fatalf("missing %v env variable", key) | ||
} | ||
*value = v | ||
} |