0

When I import a package in a go application (using modules and vscode with golang plugin):

import (
   cors "goa.design/plugins/cors/dsl"
)

go automatically retrieves the package. How does go know where to get it from? I figured it simply pulls the sources from github.com, but the repository for this project is at https://github.com/goadesign/goa no . in the name. And if I change the import to:

import (
   cors "goa.design/plugins/v3/cors/dsl"
)

It retrieves the v3 package. I would gladly RTFM, but not sure which FM I need to read.

Btw: this is my second day on go so this is magic to me.

Dennie de Lange
  • 2,776
  • 2
  • 18
  • 31

1 Answers1

7

It's simple, check it out:

$> curl https://goa.design/plugins/cors/dsl
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-us">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">


  <meta name="go-import" content="goa.design/plugins git https://github.com/goadesign/plugins">
  <meta name="go-source" content="goa.design/plugins _ https://github.com/goadesign/plugins/tree/master/{/dir} https://github.com/goadesign/plugins/blob/master{/dir}/{file}#L{line}">

The key here is in the tag named "go-import". When go get requests https://goa.design/..., it hits that HTML file and knows that "goa.design/...." must be retrieved using git from https://github.com/goadesign/plugins.

Here is a good article

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103