Giter Club home page Giter Club logo

govanityurls's Introduction

Go Vanity URLs

Go Vanity URLs is a simple Go server that allows you to set custom import paths for your Go packages. It also can run on Google App Engine.

Quickstart

Install and run the binary:

$ go get -u github.com/GoogleCloudPlatform/govanityurls
$ # update vanity.yaml
$ govanityurls
$ # open http://localhost:8080

Google App Engine

Install gcloud and install Go App Engine component:

$ gcloud components install app-engine-go

Setup a custom domain for your app.

Get the application:

git clone https://github.com/GoogleCloudPlatform/govanityurls
cd govanityurls

Edit vanity.yaml to add any number of git repos. E.g., customdomain.com/portmidi will serve the https://github.com/rakyll/portmidi repo.

paths:
  /portmidi:
    repo: https://github.com/rakyll/portmidi

You can add as many rules as you wish.

Deploy the app:

$ gcloud app deploy

That's it! You can use go get to get the package from your custom domain.

$ go get customdomain.com/portmidi

Running in other environments

You can also deploy this as an App Engine Flexible app by changing the app.yaml file:

runtime: go
env: flex

This project is a normal Go HTTP server, so you can also incorporate the handler into larger Go servers.

Configuration File

host: example.com
cache_max_age: 3600
paths:
  /foo:
    repo: https://github.com/example/foo
    display: "https://github.com/example/foo https://github.com/example/foo/tree/master{/dir} https://github.com/example/foo/blob/master{/dir}/{file}#L{line}"
    vcs: git
Key Required Description
cache_max_age optional The amount of time to cache package pages in seconds. Controls the max-age directive sent in the Cache-Control HTTP header.
host optional Host name to use in meta tags. If omitted, uses the App Engine default version host or the Host header on non-App Engine Standard environments. You can use this option to fix the host when using this service behind a reverse proxy or a custom dispatch file.
paths required Map of paths to path configurations. Each key is a path that will point to the root of a repository hosted elsewhere. The fields are documented in the Path Configuration section below.

Path Configuration

Key Required Description
display optional The last three fields of the go-source meta tag. If omitted, it is inferred from the code hosting service if possible.
repo required Root URL of the repository as it would appear in go-import meta tag.
vcs required if ambiguous If the version control system cannot be inferred (e.g. for Bitbucket or a custom domain), then this specifies the version control system as it would appear in go-import meta tag. This can be one of git, hg, svn, or bzr.

govanityurls's People

Contributors

ahmetb avatar philips avatar pitasi avatar rakyll avatar riannucci avatar xoebus avatar zombiezen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

govanityurls's Issues

path is not correctly redirected to the sub package

By using the configuration below:

host: rakyll.pizza

paths:
  /:
    repo: https://github.com/rakyll/pizza

rakyll.pizza/pineapple should server github.com/rakyll/pizza/pinapple but it is redirecting to the root of the repo.

$ curl rakyll.pizza/pineapple
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="rakyll.pizza git https://github.com/rakyll/pizza">
<meta name="go-source" content="rakyll.pizza https://github.com/rakyll/pizza https://github.com/rakyll/pizza/tree/master{/dir} https://github.com/rakyll/pizza/blob/master{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url=https://godoc.org/rakyll.pizza">
</head>
<body>
Nothing to see here; <a href="https://godoc.org/rakyll.pizza">see the package on godoc</a>.
</body>
</html>%

please set cache headers

Thank you for this package, it makes setting up a vanity import path pretty easy indeed.

I noticed that no cache headers are set in any responses:

% curl -v <url>
< HTTP/2 200 
< content-type: text/html; charset=utf-8
< x-cloud-trace-context: e11dd858ab85c26bd488a27ac5deb139;o=1
< date: Sun, 24 Sep 2017 07:38:12 GMT
< server: Google Frontend
< content-length: 566
< alt-svc: quic=":443"; ma=2592000; v="39,38,37,35"
< 
<!DOCTYPE html>
[…]

When using CloudFlare in front of AppEngine, it is beneficial to set caching headers to reduce traffic to AppEngine. Currently, every request needs to go to AppEngine, even though the response will be exactly the same.

I suggest that cache headers should be included with every response, with the default cache time being 24 hours or so (configurable). This should be a good default, given how rarely the config changes in practice.

See https://support.cloudflare.com/hc/en-us/articles/202775670-How-Do-I-Tell-Cloudflare-What-to-Cache- for which headers CloudFlare respects.

Thank you for considering.

Remove the vendor directory?

The lowest version number this seems to be building with is 1.12, so in theory the vendor directory could be removed. Is there a reason it needs to stay?

Prefix wildcard matching is required

Currently, govanityurls looks for an exact prefix match for the paths provided in the configuration file.

host: my.org

paths:
   - /example/helloworld
        repo: ....
   - /
        repo: .... 

If user asks for my.org/x, govanityurls return a 404 instead of matching it with the second rule.

What's expected is that we should match /x with the / rule.

http (non-https) urls still redirecting to godoc.org

Recently I pulled in the changes from #33 and #34.

https urls (ex: https://gotest.tools/) redirect properly to https://pkg.go.dev/
However http urls (ex http://gotest.tools/) continue to redirect to https://godoc.org

I attempted to set secure: always in the app.yaml, but that has not fixed the problem.

I confirmed in the appengine logs that the requests to http are going to the same service and version. No instances of older versions are running. The main difference in the logs seems to be that https requests get a 204 response code, and the http requests get a 200 response code.

I was previously already running with runtime: go112, but I may not have noticed the requests being handled incorrectly because nothing else had changed in the application.

Do you know if the upgrade to go1.12 runtime may be causing this problem, or how else I might be able to debug? I tried looking around stackoverflow but found nothing relevant.

I understand this issue may be an appengine bug, and not related to this project, but I thought I would ask here in case someone else using this project had the same problem.

[feature] regex/wildcard match in vanity.yaml

We have a use case where we want to transform
code.corp.com/a/b -> code.corp.com/a/b-real-repo.git
instead of doing this for every repo, can we have a wildcard match to do this for all import paths?

module required error when get module in multi module repo mode

Hi, I have a module mode repo like this:

// repo: https://git.mycompany.com/dev/pkg.git

├── README.md
├── go.mod    // go.mycompany.com/pkg
├── util
│   ├── go.mod   // go.mycompany.com/pkg/util
│   ├── go.sum
│   ├── xx.go
├── log
│   ├── go.mod    // go.mycompany.com/pkg/log
│   ├── go.sum
│   └── xx.go

I have add config in vanity.yaml

paths:
  /pkg/util:
    repo: https://git.mycompany.com/dev/pkg

but When execute command go get -v go.company.com/pkg/util , I got error

get "go.company.com/pkg": found meta tag get.metaImport{Prefix:"go.company.com/pkg", VCS:"git", RepoRoot:"https://git.mycompany.com/dev/pkg"} at //git.mycompany.com/pkg?go-get=1
get "go.company.com/pkg/util": found meta tag get.metaImport{Prefix:"go.company.com/pkg/util", VCS:"git", RepoRoot:"https://git.mycompany.com/dev/pkg"} at //git.mycompany.com/pkg/util?go-get=1
go: go.mycompany.com/pkg/util master => v0.1.2-0.20210120054534-86b99a469841
go get: go.mycompany.com/pkg/[email protected]: parsing go.mod:
	module declares its path as: go.mycompany.com/pkg
	        but was required as: go.mycompany.com/pkg/util

Is there any idea to resolve it ?

pages are not rendered with custom domain on app engine

$ curl rakyll.pizza/cheese
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="rakyllpizza.appspot.com/cheese git https://github.com/rakyll/cheese">
<meta name="go-source" content="rakyllpizza.appspot.com/cheese https://github.com/rakyll/cheese https://github.com/rakyll/cheese/tree/master{/dir} https://github.com/rakyll/cheese/blob/master{/dir}/{file}#L{line}">
<meta http-equiv="refresh" content="0; url=https://godoc.org/rakyllpizza.appspot.com/cheese">
</head>
<body>
Nothing to see here; <a href="https://godoc.org/rakyllpizza.appspot.com/cheese">see the package on godoc</a>.
</body>
</html>%

Note the URLs are rakyllpizza.appspot.com/cheese not rakyll.pizza/cheese.

Allow Git paths to specify a default branch

I'd like to add support for having paths correspond with a particular branch of a repository. This would enable, for instance, a custom import path to allow gopkg.in-style versioning. A hypothetical example:

host: example.com
paths:
  /foo:
    repo: https://github.com/example/foo
  /foo.v2:
    repo: https://github.com/example/foo
    branch: v2

and then gradually the branches could be swapped:

host: example.com
paths:
  /foo:
    repo: https://github.com/example/foo
    branch: v1
  /foo.v2:
    repo: https://github.com/example/foo

I propose taking the approach used by gopkg.in: point the source URL to a dummy URL on the govanityurls server, rewrite the refs response, then HTTP 301 over to the real Git repository.

I think a similar approach could be added for Mercurial later, but I'd rather focus on Git right now.

@rakyll WDYT?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.