How to import a local file in my main package [closed] - go

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Let's say, I have the following structure.
export $GOPATH = ~/workspace/go
Directory-Tree:
~/workspace
+ go
+ src
+ example
+ exp1
- main.go
- client.go
+ utils
- my_utils.go
In the file main.go i'd like to import 'client.go' and 'utils/my_utils.go'.
How to do that?
import {
"./client.go"
}
will give me
local import "./client.go" in non-local package
The same happens with any other file in subdirectories like my "utils" folder.
I've read a lot about this error message and about the GOPATH. However, coming from NodeJS and PHP and C++ I really still don't understand this concept of how GoLang will handle file imports and need some further clarification here.
I've read also that people where going to import everything from "GitHub.com", but it makes no sense for me to first push my code to GitHub before I can test it in my local project.
By the way, I'm also curious why go get will not fetch all sub-dependencies together with the specific library that will be fetch with go get?

I've read also that people where going to import everything from "GitHub.com", but it makes no sense for me to first push my code to GitHub before I can test it in my local project.
You don't have to push it anywhere before you can test it. You only have to choose what your import path is, and then put your code in GOPATH accordingly (or use go mod init with Go 1.11+, which lets you place your code anywhere in the filesystem you want). But you still have to pick that import path — even if you decide to change it later.
By the way, I'm also curious why go get will not fetch all sub-dependencies together with the specific library that will be fetch with go get?
It does.

Related

Problems to use packages in Go [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
I'm having problems to use packages. I a following literally the steps I find online, but I have an error message.
I have this package in GOPATH:
go/src/greet/day.go
package greet
var morning = "Good morning"
var Morning = "hey" + morning
I want to import it in my code:
go/src/app/entry.go
package main
import ("fmt"
"greet")
func main(){
fmt.Println(greet.Morning)
}
When I run entry.go, I receive this message:
entry.go:4:3: package greet is not in GOROOT (/usr/local/go/src/greet)
Does anybody how to fix it?
Thank you.
GOPATH isn't really used anymore. You can use a different directory and run go mod init greet. This will create a new module "greet" in that folder, and from within that module you can import packages using import "{module name}/{package path}". It is a best practice to use the folder name as the package name, so the import path matches the folder names (except for main packages).
Additionally, if your module lives in a git repository, your module name should be the path to the git repository. for example, go mod init github.com/jaenmo/myrepo.
within your module make a folder for your main package. You should be able to import using your module name.

Why does 'go vet' complain only in some versions of Go? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Today I included 'go vet' in one of my pipelines that builds a go service. I wonder why go vet's output on my local machine is different from the one that runs on the CI server.
I figured out that the go version differs - at least a bit. My local Go version is 1.12.4 and the CIs is version 1.12.7. This fact would explain the different behaviour, but I don't get why this happens!
There is the smell:
type Something struct {
...
BatteryNumber string `json:"number"`
...
}
type SomethingWithBattery struct {
Something
Number string `json:"number"`
...
}
So, two times 'number' in the struct tags, because Something-struct is nested SomethingWithBattery - 1.12.4 complains, 1.12.7 does not. Why?
Go 1 and the Future of Go Programs
Tools
Finally, the Go toolchain (compilers, linkers, build tools, and so on)
is under active development and may change behavior. This means, for
instance, that scripts that depend on the location and properties of
the tools may be broken by a point release.
go vet is under active development and recently it has been rewritten. There is no compatibility guarantee for tools, only the language.
cmd/vet: Consider reverting tag conflict for embedded fields #30465
go vet fails due to intended shadowing of embedded fields with json
tags.
Also, bug fixes are applied to the Go tools. For example, Issue 30465.

How to get stats on go packages? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I am trying to track and understand the download stats for various go packages to evaluate the download patter over time for the go driver published and released by my team.
Something similar to npm-stats
https://npm-stat.com/
I see similar stats available for pip-python and npm.
https://npm-stat.com/
That may happen once the Go Notary service described in "Go Modules in 2019" is in place:
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.
If statistics were to be produced, the Go notary would be a reliable source (for public packages)
Go doesn't have a centralized package registry such as npm or pip.
Also, go dependency management is still not "unified", some use dep some glide or go mod. All of these rely on version control software such as git.
If your package is on Github, you could check the Insights > Traffic tab and see unique cloners for example.
Another solution might be to implement a proxy to your git server to track clones.
You Can't do this.
As those are developed as part of Go language. Like npm packages you are not downloading it.
try gocenter.io, it includes download stats for all modules available. Example - logrus was downloaded 544k+ times - https://search.gocenter.io/github.com~2Fsirupsen~2Flogrus/info?version=v1.4.3-0.20191026113918-67a7fdcf741f

No such module Parse errors [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
screenshot
I'm getting an error saying "no such module Parse" after downloading SDK( Parse) and adding frameworks and dependencies to my App. When I added "import Parse" to AppleDelegate.swift but it caused the error.
I attached a screenshot above.
Can anyone help me with this?
Thank you so much
Remove the framework completely by clicking delete in your framework folder (in Xcode, not finder)
Make sure that there is no trace of the framework in finder in your project folder. (I had the same problem and found out that I had duplicates in my Xcode project folder)
Restart Xcode
Re download the frameworks and put into your project through Xcode (not by dragging them in finder)
Clean project
It should run after doing these steps. I had the same problem as you and found restarting Xcode and reloading the frameworks worked. Hopefully this also works for you.
possible duplicate isn't an issue, it means that your question has been asked before ;)
This is what I think you should do:
Your framework is most likely written in Objective C and therefore your cant import it so easily.
Inside your framework create a header file:
Then you write this in the header file to import the parse modules I think:
#import <Parse.h>
And now you should be able to do:
import Parse
Don't forget this:
Go to your main project -> Build Phases -> Link Binary With Libaries -> add Parse there.
I am not sure how the parse module is called, so inside your framework, check how to main file is called (most likely something like parse.h) and replace that with the code inside the <...>

Go: how many packages per project [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
While working on my Go project today, I realised I had ran into a small problem. I had a package that had a struct that held a pointer to a struct from another package. However, that package also made use of a struct from the other package. In C and C++, this wouldn't pose an issue, as I'd use a header guard. However, in Go, such a program won't compile due to infinite import recursion.
This made me wonder, are there too many packages in my project? Should I favour bigger packages? I've always been told that each package should be specifically focused on one thing.
Right now, my structure is like this.
game/ <-- imports engine, needs to access the resource manager a lot
video/ <-- rendering goes here
renderer.go
shader.go
scene.go
...
engine/ <-- imports video, file, etc
root.go <-- contains a Root struct, handles initialisation etc
resource.go
...
file/
dds.go
config.go
resource_list.go
script.go
...
main.go
...
That said, here are my questions:
How would you solve this? Would you combine the video and engine packages? Redesign your program so that video no longer depends on engine?
How do you decide when it's appropriate to make a new package? Do you base it on functionality? Do you group it by category?
How much use do you make of the main package? I personally tend to get out of it as quickly as possible, maybe because I'm too used to OOP.
As these questions are rather broad and project-specific, I can only hope this is of any help:
Personally, I would try to create a third package on which both video and engine can rely. Depending on the project though, this might be a difficult thing to do, and they might need to be merged.
A new package is usually about one specific task. Depending on the project, this might be database I/O, including all models as well - but it might also be a package that's just about reading configuration files from the disk.
As I've built mostly web-apps, I use the main package to get things started: listening to ports, calling other functions, making sure database connections are closed properly, etc.
Example (not sure if helpful? ) :
I once had a package that was just about configurations (config), which referred to the rest of the packages (for some reason). The other packages however, depended on those configurations inside config. This is where the main package can come in handy: linking the config package with the other packages, by means of parameters.
The comment from VonC is also very useful and elaborate. It will probably help you more than this.

Resources