Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
runtime: go
api_version: go1

runtime: go121
handlers:
- url: /.*
script: _go_app
script: auto
42 changes: 0 additions & 42 deletions appengine.go

This file was deleted.

5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/thisissoon/govanityurls

go 1.12

require gopkg.in/yaml.v2 v2.2.2
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
6 changes: 4 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@ func newHandler(config []byte) (*handler, error) {
display: e.Display,
vcs: e.VCS,
}
isGithub := strings.HasPrefix(e.Repo, "https://github.com/")
isGitlab := strings.HasPrefix(e.Repo, "https://gitlab.com/")
switch {
case e.Display != "":
// Already filled in.
case strings.HasPrefix(e.Repo, "https://github.com/"):
case isGithub, isGitlab:
pc.display = fmt.Sprintf("%v %v/tree/master{/dir} %v/blob/master{/dir}/{file}#L{line}", e.Repo, e.Repo, e.Repo)
case strings.HasPrefix(e.Repo, "https://bitbucket.org"):
pc.display = fmt.Sprintf("%v %v/src/default{/dir} %v/src/default{/dir}/{file}#{file}-{line}", e.Repo, e.Repo, e.Repo)
Expand All @@ -82,7 +84,7 @@ func newHandler(config []byte) (*handler, error) {
if e.VCS != "bzr" && e.VCS != "git" && e.VCS != "hg" && e.VCS != "svn" {
return nil, fmt.Errorf("configuration for %v: unknown VCS %s", path, e.VCS)
}
case strings.HasPrefix(e.Repo, "https://github.com/"):
case isGithub, isGitlab:
pc.vcs = "git"
default:
return nil, fmt.Errorf("configuration for %v: cannot infer VCS from %s", path, e.Repo)
Expand Down
18 changes: 14 additions & 4 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ func TestHandler(t *testing.T) {
goImport: "example.com/gopdf hg https://bitbucket.org/zombiezen/gopdf",
goSource: "example.com/gopdf https://bitbucket.org/zombiezen/gopdf https://bitbucket.org/zombiezen/gopdf/src/default{/dir} https://bitbucket.org/zombiezen/gopdf/src/default{/dir}/{file}#{file}-{line}",
},
{
name: "display Gitlab inference",
config: "host: example.com\n" +
"paths:\n" +
" /portmidi:\n" +
" repo: https://gitlab.com/rakyll/portmidi\n",
path: "/portmidi",
goImport: "example.com/portmidi git https://gitlab.com/rakyll/portmidi",
goSource: "example.com/portmidi https://gitlab.com/rakyll/portmidi https://gitlab.com/rakyll/portmidi/tree/master{/dir} https://gitlab.com/rakyll/portmidi/blob/master{/dir}/{file}#L{line}",
},
{
name: "Bitbucket Git",
config: "host: example.com\n" +
Expand Down Expand Up @@ -237,10 +247,10 @@ func TestPathConfigSetFind(t *testing.T) {
want: "/y",
},
{
paths: []string{"/example/helloworld", "/", "/y", "/foo"},
query: "/x/y/",
want: "/",
subpath: "x/y/",
paths: []string{"/example/helloworld", "/", "/y", "/foo"},
query: "/x/y/",
want: "/",
subpath: "x/y/",
},
{
paths: []string{"/example/helloworld", "/y", "/foo"},
Expand Down
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//+build !appengine

package main

import (
"fmt"
"io/ioutil"
"log"
"net/http"
Expand All @@ -42,7 +41,13 @@ func main() {
log.Fatal(err)
}
http.Handle("/", h)
if err := http.ListenAndServe(":8080", nil); err != nil {

port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
if err := http.ListenAndServe(fmt.Sprintf(":%s", port), nil); err != nil {
log.Fatal(err)
}
}
Expand Down