How can I import a library from github to GO playground? - go

Hi I want to import a 3rd party library to GO playground, I saw an answer for this question: https://stackoverflow.com/a/27813778/6638204 but it said that this can not be done, but the xiam/go-playground library on github states that it can do this. I tried using it but I did not understand what should I exactly do. I successfully installed the library and used it to run programs that do not need third party libraries. but I did not get how can I import a third party library. ps: I have docker installed in my machine

The answer is still the same: you can't do that on the "official" Go Playground (at https://play.golang.org/).
If you or someone else runs a custom, modified version of the Go Playground: then the answer is you can do there whatever is allowed, which may include the usage of external libraries which the custom engine may go get prior to compilation and execution.
Also see related question: Which packages may be imported in the go playground?

You might be able to do it since May 14th, 2019
See this tweet (from Brad Fitzpatrick)!
The #golang playground now supports third-party imports, pulling them in via https://proxy.golang.org/
Example: https://play.golang.org/p/eqEo7mqdS9l 🎉
Multi-file support & few other things up next.
Report bugs at golang/go issue 31944, or here on the tweeters.
But that means you have published your package deliverable in such a way it is reference by the Go proxy.

Related

What is user interface for JuliaHub/CUDD_jll

Julia has a package for binary decision diagrams called CUDD_jll available from JuliaHub. The package is able to install and compile on the Apple M1 architecture. It does appear to install and compile on macOS v13 running Julia v1.82. But the user interface from an older package CUDD does not appear to be compatible with CUDD_jll.
What is needed is a test or examples revealing user commands for initializing cudd, defining logical variables, and the basic operations of AND, OR, NOT.
Does anyone have such information they will share?
_jll packages are generally not meant to be used directly, they're backend dependencies that will be automatically installed when you add a package that uses them.
In this case, CUDD.jl is the package you want to install and work with. That will automatically install CUDD_jll as a dependency and use it. Actually, the current CUDD.jl doesn't yet use CUDD_jll as a backend. It instead does its own download of the CUDD library, from a source that doesn't provide M1-compatible binaries. CUDD_jll is a recent effort to change that. It does provide binaries for the M1 architecture, but is yet to be merged in as a backend.
In the meantime, you can try ] add CUDD#update-to-yggdrasil to directly add the branch that uses CUDA_jll as the backend, and see if that works for you. (Once the PR gets merged, you can remove this branch-specific dependency and ] add CUDD like before.)
The Apple M1 system is not compatible with CUDD. My mistake, sorry.

How to run pkg.go.dev locally as a godoc replacement?

godoc has been removed from the go standard install since 1.12 and looks like it wont be updated anytime soon. pkg.go.dev at least appears to be its successor. It also has additional documentation features like grabbing the README.md file and rendering it in the documentation page.
For these reasons I was hoping to switch over to using pkg.go.dev locally to view and create documentation for small internal packages. The major issue is that unlike godoc there does not seem to be a clear usage guide. I also do not know if pkpg.go.dev is completely overkill for this task. So I would like to know:
Can and should pkg.go.dev be used as a local godoc replacement?
If yes, how would I run it for this task?
Run pkgsite locally.
go install golang.org/x/pkgsite/cmd/pkgsite#latest && pkgsite
References:
https://tip.golang.org/doc/comment
https://pkg.go.dev/golang.org/x/pkgsite/cmd/pkgsite
You can use the x/tools/godoc that has the previous godoc tool
Running godoc [1] on its own worked for me, but was really slow because it generates docs for every single package in the standard library, while I only care about the local package that I am working on. To that end, if your package is in a folder called something, you can move the folder so that it looks like this:
godoc/src/something
Then, go to the godoc folder, and run
godoc -goroot .
Then, browse to localhost:6060. Alternatively, another site is available for
Go docs [2].
https://github.com/golang/tools/tree/master/cmd/godoc
https://godocs.io

How do you know if your github golang repo is being used?

I have an API client written in go. It's on github at the moment with about 4 stars, but I have no idea whether there are other developers using this package.
There's nothing listed if you go to the repository's Insights->Dependency Graph. I don't think that this is enabled for go projects.
What's the best way to find out whether a golang package is being imported by another golang package/application?
You can't really tell what private projects use your repo.
For public modules, you may use go.dev. Go to pkg.go.dev, enter your package import path, then click on the "Imported By" tab.

Where to find golang modules?

I am from node.js ecosystem.
Golang has released its module system finally and I have read some articles about it:
https://blog.golang.org/using-go-modules
https://github.com/golang/go/wiki/Modules
But, after that, I still didn't find a place like npmjs.com where I can find available go modules.
There is no central repository yet, but note that the module support is still experimental in Go 1.12. It will be enabled by default in Go 1.13 (scheduled for August 2019).
Check out The Go Blog: Go Modules in 2019.
For publicly-available modules, we intend to run a service we call a notary that follows the module index log, downloads new modules, and cryptographically signs statements of the form “module M at version V has file tree hash H.” The notary service will publish all these notarized hashes in a queryable, Certificate Transparency-style tamper-proof log, so that anyone can verify that the notary is behaving correctly. This log will serve as a public, global go.sum file that go get can use to authenticate modules when adding or updating dependencies.
We are aiming to have the go command check notarized hashes for publicly-available modules not already in go.sum starting in Go 1.13.
and
Module Discovery
Finally, we mentioned earlier that the module index will make it easier to build sites like godoc.org. Part of our work in 2019 will be a major revamp of godoc.org to make it more useful for developers who need to discover available modules and then decide whether to rely on a given module or not.
Big Picture
This diagram shows how module source code moves through the design in this post.
There is no central repository for Go modules. As long as you follow the conventions for publishing Go packages (see PackagePublishing), the go tools will be able to fetch your package/module, no matter where you published it.
In order to discover what is already out there in the Go universe, a good starting point is Awesome Go, a curated list of awesome Go packages/modules.
https://search.gocenter.io can be used to search for Go modules, know more about popularity of a module version and even help module authors connect with their consumers. This is GA since end of January 2019 and globally available.
I had the same question. If you start off with the built-in packages (https://golang.org/pkg/), and you follow some non-obvious links, you eventually end up here:
https://pkg.go.dev/

Go Wants to Import Package From Comment [duplicate]

New Go programmer here -- apologies if this is well worn territory, but my google searching hasn't turned up the answer I'm looking for.
Short Version: Can I, as a programmer external to the core Go project, force my packages to be imported with a specific name. If so, how?
Long Version: I recently tried to install the bcrypt package from the following GitHub repository, with the following go get
go get github.com/golang/crypto
The package downloaded correctly into my workspace, but when I tried to import it, I got the following error
$ go run main.go main.go:10:2: code in directory /path/to/go/src/github.com/golang/crypto/bcrypt expects import "golang.org/x/crypto/bcrypt"
i.e. something told Go this package was supposed to be imported with golang.org/x/crypto/bcrypt. This tipped me off that what I actually wanted was
go get golang.org/x/crypto/bcrypt
I'd like to do something similar in my own packages — is this functionality built into Go packaging? Or are the authors of crypto/bcrypt doing something at runtime to detect and reject invalid package import names?
Yes it's built in, I can't seem to find the implementation document (it's a relatively new feature in 1.5 or 1.6) however the syntax is:
package name // import "your-custom-path"
Example: https://github.com/golang/crypto/blob/master/bcrypt/bcrypt.go#L7
// edit
The design document for this feature is https://docs.google.com/document/d/1jVFkZTcYbNLaTxXD9OcGfn7vYv5hWtPx9--lTx1gPMs/edit
// edit
#JimB pointed out to https://golang.org/cmd/go/#hdr-Import_path_checking, and in the go1.4 release notes: https://golang.org/doc/go1.4#canonicalimports

Resources