‹ BackHN Continuity

Thread

Don't couple your Go code to GitHub

325 points · 177 comments · birdculture

  1. dewey · · focus · HN ↗
    > That is, if you move your git hosting to GitLab then you have to change your code!

    You can also just use "replace github.com/example/example => gitlab.com/example/example" in your go.mod file and everything will keep working. That seems like a very pre-mature optimization for something that doesn't really matter.

    1. kelnos · · focus · HN ↗
      What about everyone else using your code? You are going to ask them all to update their code as well? Many of them probably won't realize, and will get stuck on an old version that never gets updated, even to fix bugs and security issues.
      1. jayd16 · · focus · HN ↗
        By this logic, those folks should be pointing to their own hosted mirrors of the project, no?
      2. quacker · · focus · HN ↗
        I think the migration can be made pretty easy for users with deprecation notices and the `go fix` tool. Better explained in [1] (I have not tried it myself).

        The idea is: the package maintainer pushes a final version of the old package that is a shim, and which has a deprecation notice. The shim imports the new package, and forwards all calls to the new package (and I suppose type aliases and variable aliases as well). The shim includes `//go:fix inline` annotations on all exported symbols, so that when users run `go fix` it rewrites their code to use the new package, by inlining their usages of the old package (which is now simply a shim that references the new package).

        Not perfect. There is still a bit of a discoverability problem. Not all tooling warns on deprecated packages/functions (go toolchain doesn't, but gopls and staticcheck do). And users need to know to run `go fix`.

        1: <a href="https:&#x2F;&#x2F;go.dev&#x2F;blog&#x2F;inliner#example-renaming-ioutilreadfile" rel="nofollow">https:&#x2F;&#x2F;go.dev&#x2F;blog&#x2F;inliner#example-renaming-ioutilreadfile

      3. Cthulhu_ · · focus · HN ↗
        As library maintainer, you can mark the last old domain version as deprecated:

            &#x2F;&#x2F; Deprecated: use example.com&#x2F;mod&#x2F;v2 instead.
            module example.com&#x2F;mod
        
        As library user, it&#x27;s your responsibility to keep your stuff updated. There may also be utilities in the various automatic dependency updaters that can migrate these things.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.