Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-top level imports #14

Closed
prashantv opened this issue Oct 1, 2016 · 10 comments
Closed

Support non-top level imports #14

prashantv opened this issue Oct 1, 2016 · 10 comments

Comments

@prashantv
Copy link

I have a very simply dummy program,

package main

import _ "go.uber.org/yarpc/transport"

func main() {
}

I have this in a completely clean GOPATH, and I run go get ., which should download all imports. This fails with:

> go get .
package go.uber.org/yarpc/transport: unrecognized import path "go.uber.org/yarpc/transport" (parse https://go.uber.org/yarpc/transport?go-get=1: no go-import meta tags)

This works fine for non-vanity imports.

@HelloGrayson
Copy link
Contributor

HelloGrayson commented Oct 1, 2016

With the current approach, you must install an entire library before you can use subpackages.

I can think of 4 ways to add this type of support:

  1. Explicitly list subpackages of a package in the sally.yaml - of course you'd only need to do this for subpackages you'd like to support installing directly. In most cases, I imagine the entire library should be installed before using subpackages.
  2. Dynamically determine subpackages when generating static site - this has the benefit of being "complete", but can get stale just like item 1.
  3. Change sally to a Go server that can accept dynamic requests that always serves the right html regardless of the URL. This is probably the biggest challenge since it means changing from Github Pages to something that can serve Go.
  4. Update the go tool to resolve the root package to determine if its a vanity import or not, then crawl to the actual location of the subpackage

This isn't really an issue with YARPC or ThriftRW since we want you installing the root package in order to use the library. Is that different with Zap or UberFX? Trying to think of what type of libraries want you to start from a subpackage only. Perhaps item 1 is sufficient in that case.

@prashantv
Copy link
Author

I think the solution is much simpler than that, we just need to return the same page for all URLs under the root package. The only difference should be the godoc page we direct to.

E.g., for grpc, the root:

$ curl -s google.golang.org/grpc?go-get=1
<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="google.golang.org/grpc git https://github.com/grpc/grpc-go">

<meta name="go-source" content="google.golang.org/grpc https://github.com/grpc/grpc-go https://github.com/grpc/grpc-go/tree/master{/dir} https://github.com/grpc/grpc-go/tree/master{/dir}/{file}#L{line}">

<meta http-equiv="refresh" content="0; url=https://godoc.org/google.golang.org/grpc">
</head>
<body>
Nothing to see here. Please <a href="https://godoc.org/google.golang.org/grpc">move along</a>.
</body>
</html>

For a subpackage that exists:

$ curl -s google.golang.org/grpc/transport?go-get=1
<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="google.golang.org/grpc git https://github.com/grpc/grpc-go">

<meta name="go-source" content="google.golang.org/grpc https://github.com/grpc/grpc-go https://github.com/grpc/grpc-go/tree/master{/dir} https://github.com/grpc/grpc-go/tree/master{/dir}/{file}#L{line}">

<meta http-equiv="refresh" content="0; url=https://godoc.org/google.golang.org/grpc/transport">
</head>
<body>
Nothing to see here. Please <a href="https://godoc.org/google.golang.org/grpc/transport">move along</a>.
</body>
</html>

And a subpackage that does not exist:

$ curl -s google.golang.org/grpc/transportdoesnotexist?go-get=1
<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="google.golang.org/grpc git https://github.com/grpc/grpc-go">

<meta name="go-source" content="google.golang.org/grpc https://github.com/grpc/grpc-go https://github.com/grpc/grpc-go/tree/master{/dir} https://github.com/grpc/grpc-go/tree/master{/dir}/{file}#L{line}">

<meta http-equiv="refresh" content="0; url=https://godoc.org/google.golang.org/grpc/transportdoesnotexist">
</head>
<body>
Nothing to see here. Please <a href="https://godoc.org/google.golang.org/grpc/transportdoesnotexist">move along</a>.
</body>
</html>

Note how the go-import and go-source meta tags are exactly the same in all cases.

@HelloGrayson
Copy link
Contributor

HelloGrayson commented Oct 1, 2016

@prashantv nice, except that Sally is a static site generator.

It might be that item 3 is the only way - let me research a bit.

Worse case I just rework sally and get go.uber.org on AWS - shouldn't be too big a deal.

This was referenced Oct 1, 2016
@HelloGrayson
Copy link
Contributor

OK - I've reworked Sally into an HTTP server in #15

This makes Sally behave the same as google.golang.org/grpc.

Non-existent package:

$ curl localhost:8080/nonexistent

404 page not found

Existent package:

$ curl localhost:8080/yarpc

<!DOCTYPE html>
<html>
    <head>
        <meta name="go-import" content="go.uber.org/yarpc git https://github.com/yarpc/yarpc-go">
        <meta name="go-source" content="go.uber.org/yarpc https://github.com/yarpc/yarpc-go https://github.com/yarpc/yarpc-go/tree/master{/dir} https://github.com/yarpc/yarpc-go/tree/master{/dir}/{file}#L{line}">
        <meta http-equiv="refresh" content="0; url=https://godoc.org/go.uber.org/yarpc">
    </head>
    <body>
        Nothing to see here. Please <a href="https://godoc.org/go.uber.org/yarpc">move along</a>.
    </body>
</html>

With trailing slash (#9):

$ curl localhost:8080/yarpc/

<!DOCTYPE html>
<html>
    <head>
        <meta name="go-import" content="go.uber.org/yarpc git https://github.com/yarpc/yarpc-go">
        <meta name="go-source" content="go.uber.org/yarpc https://github.com/yarpc/yarpc-go https://github.com/yarpc/yarpc-go/tree/master{/dir} https://github.com/yarpc/yarpc-go/tree/master{/dir}/{file}#L{line}">
        <meta http-equiv="refresh" content="0; url=https://godoc.org/go.uber.org/yarpc/">
    </head>
    <body>
        Nothing to see here. Please <a href="https://godoc.org/go.uber.org/yarpc/">move along</a>.
    </body>
</html>

With deep path:

$ curl localhost:8080/yarpc/hahahaha

<!DOCTYPE html>
<html>
    <head>
        <meta name="go-import" content="go.uber.org/yarpc git https://github.com/yarpc/yarpc-go">
        <meta name="go-source" content="go.uber.org/yarpc https://github.com/yarpc/yarpc-go https://github.com/yarpc/yarpc-go/tree/master{/dir} https://github.com/yarpc/yarpc-go/tree/master{/dir}/{file}#L{line}">
        <meta http-equiv="refresh" content="0; url=https://godoc.org/go.uber.org/yarpc/hahahaha">
    </head>
    <body>
        Nothing to see here. Please <a href="https://godoc.org/go.uber.org/yarpc/hahahaha">move along</a>.
    </body>
</html>

With really deep path:

$ curl localhost:8080/yarpc/hahahaha/blahblah

<!DOCTYPE html>
<html>
    <head>
        <meta name="go-import" content="go.uber.org/yarpc git https://github.com/yarpc/yarpc-go">
        <meta name="go-source" content="go.uber.org/yarpc https://github.com/yarpc/yarpc-go https://github.com/yarpc/yarpc-go/tree/master{/dir} https://github.com/yarpc/yarpc-go/tree/master{/dir}/{file}#L{line}">
        <meta http-equiv="refresh" content="0; url=https://godoc.org/go.uber.org/yarpc/hahahaha/blahblah">
    </head>
    <body>
        Nothing to see here. Please <a href="https://godoc.org/go.uber.org/yarpc/hahahaha/blahblah">move along</a>.
    </body>
</html>

@prashantv
Copy link
Author

I think the HTTP server is the only way to fix the issue correctly. However, the barrier to using sally goes up significantly with this approach. Is option #2 something we could still support? E.g., when you run sally, it figured out the subpackages and adds them automatically. Re-running is all that's needed if there's a new package.

@HelloGrayson
Copy link
Contributor

@prashantv I had thought the same thing, but switching to a server was easy: #15

I think it's important we get Sally working seamlessly - I don't want a bunch of customers stumbling over confusing go tool errors, even if the current setup does work.

I'm going to spend a bit of time today on a Travis -> AWS continuous deployment flow using go.graysonkoonce.com - if that ends up being easy, then I think this is a viable path.

@prashantv
Copy link
Author

@breerly Switching to a HTTP server is easy in Go, but it's also harder for more users to use since the overhead goes from: "Use this tool + GitHub pages" to "Use this tool, and run it on some hosting service" (which now means yet another service to deploy, monitor, pay for hosting, etc).

It really depends on the reach we'd like for sally. For my personal projects, I'd likely not use sally if it required hosting another binary somewhere, but would definitely consider it if it was super easy with GitHub pages. What do you think?

@HelloGrayson
Copy link
Contributor

HelloGrayson commented Oct 2, 2016

@prashantv I think what I'd like to do is support both modes. For go.uber.org, I want it to be completely seamless, and so I'm ok hooking it up as a server.

I think we should make it work as a static site generator for Github Pages at the same time. In that mode, the best we can likely do is dynamically determine the import paths and create the right static site structure from there.

@prashantv
Copy link
Author

Yep, that'd be ideal, exactly what I was thinking :)

@ascandella
Copy link

Ok cool, sounds like we're set to move uberfx to go.uber.org/fx then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants