In Eclipse RCP, Package A is dependent on Package B. Then How To visible Package A classes to Package B
Related
I would like to use the following function in my controller https://github.com/openshift/machine-api-operator/blob/05041eaab5a6b9e22dd26df421d8d51050c39072/pkg/controller/vsphere/util.go#L221
Thefore in my code I do the following import
package controllers
import (
"context"
vsphere "github.com/openshift/machine-api-operator/pkg/controller"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
However, when I do go mod tidy, I get the following error:
bitbucket.bit.admin.ch/BOSC/bosc-drs-vm-group-controller/controllers imports
github.com/openshift/machine-api-operator/pkg/controller imports
github.com/openshift/machine-api-operator/pkg/controller/machinehealthcheck imports
sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1: module sigs.k8s.io/cluster-api#latest found (v1.3.2), but does not contain package sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1
bitbucket.bit.admin.ch/BOSC/bosc-drs-vm-group-controller/controllers imports
github.com/openshift/machine-api-operator/pkg/controller imports
github.com/openshift/machine-api-operator/pkg/controller/machinehealthcheck imports
github.com/openshift/machine-api-operator/pkg/apis/healthchecking/v1alpha1 imports
sigs.k8s.io/controller-runtime/pkg/runtime/scheme: module sigs.k8s.io/controller-runtime#latest found (v0.14.1), but does not contain package sigs.k8s.io/controller-runtime/pkg/runtime/scheme
It seems that there are some dependencies issues, however I am not sure how to solve them. I tried in go.mod to set sigs.k8s.io/controller-runtime to reference a branch and not to latest, but it doesn't seem that it has any effect.
require (
...
)
require (
...
sigs.k8s.io/cluster-api release-1.3 //indirect
)
How am I suppose to solve package dependencies issues?
This works:
go get github.com/openshift/machine-api-operator/pkg/controller/vsphere#master
That package is not available in #latest release.
I've added dependency to https://github.com/sjwhitworth/golearn in Golang project. I've tried to build application, however I am getting error from one of the classes from golearn - this one: https://github.com/sjwhitworth/golearn/blob/master/base/dataframe_go.go : undefined: base. I've tried to find what is the base package refering to. There is no imported package base in this file so it looks like it is import from the same package but using the package name. I mean, dataframe_go.go is in the same package (base) where is the imported struct (FixedDataGrid). How to solve this import issue?
so here is what my directory is:
go
|-src
|-ppppppSample
|-newFolderOne
|-firstSample.go
|-hello.go
|-go.mod
and here is the content of hello.go
package main
import (
"fmt"
jjj "ppppppSample/newFolderOne"
)
func main() {
fmt.Println("start to test")
fmt.Println(jjj.FirstVVVV)
}
here is the content of firstSample.go
package newFolderOne
var FirstVVVV = "Im first SSSSSSSSSSSS"
and here is my go.mod's content
module mmmmmppppp
go 1.15
when giving it the cmd go run hello.go, the terminal came out with like this:
D:\Users\eien_zheng\go\src\ppppppSample>go run hello.go
hello.go:5:2: package ppppppSample/newFolderOne is not in GOROOT (C:\Go\src\ppppppSample\newFolderOne)
So here is my question:
(since I'm new for golang, I wish you guys could understand and tolerate some of my misunderstanding)
According to my understanding to Go module (maybe it's wrong), the Go module's function is gonna let some kind of online resource be downloaded to the directory GOPATH/pkg/mod instead of existing in GOROOT.
No matter which directory your project in, your project can still import those resource from GOPATH/pkg/mod if you init Go module.
But!!, in my understanding, it still can use package system to import package around project directory, in the meantime import online resource by Go module system.
How is that when I do (mod init) for hello.go, then it loses the (basic package import function) for this project?
|--src
|--sample
|--newFolder
|-firstSample.go (package xyz)
|--hello.go (package main import(xyz "sample/newFolder")
|--go mod (module sample go 1.15)
go mod should reference the root folder , here the root folder is |--sample
module sample
go v1.xx
inside hello.go;
package main
import ( xyz "sample/newFolder")
and make sure exported functins or variables use camelCase aka starts with BlockLetters.
Import packages within a module using the module's path:
package main
import (
"fmt"
jjj "mmmmmppppp/newFolderOne"
)
...
Run it on the Playground.
I am using go1.13.4 and below is my project structure:
src/types/type.go
src/utils/util.go
go.mod
In go.mod:
module example.com/graphql
go 1.13
require github.com/graph-gophers/graphql-go v0.0.0-20191031232829-adde0d0f76a3
In src/types/type.go:
package types
type USER struct {
...
}
In src/utils/util.go,
package utils
import (
"example.com/graphql/types"
"fmt"
"io/ioutil"
"os"
)
I got tan error when build the project:
$ go build ./...
src/utils/utils.go:4:2: cannot find module providing package example.com/graphql/types
I wonder why it can't find the package example.com/graphql/types? I am reading https://blog.golang.org/using-go-modules and I already set the module name in go.mod file at the root of my project.
With your current layout, import path of types is example.com/graphql/src/types.
go.mod should be inside src if you have that structure. Or better would be to get rid of src. go.mod must be next to the types and utils folders.
I have bundles A, B and C. A contains a package 'a' that is depended on by code in packages b and c from bundles B and C respectively.
bundle A {
package a
export-package:a
}
bundle B {
package b.a
package b.b
package b.c
package b.d
package b.e
import-package: a
export-package:b.a;uses:=a,
b.b;uses:=b.a,
b.c;uses:=b.b,
b.d;uses:=b.c,
b.e;uses:=b.d
}
bundle C {
package c
import-package: b.e,
a
}
When I update all of these bundles together, I often get uses constraint violations (Felix reporting style):
Chain 1:
C [47.1]
import: (&(osgi.wiring.package=a)(version>=1.1.0))
|
export: osgi.wiring.package=a
A [9.1]
Chain 2:
C [47.1]
import: (&(osgi.wiring.package=b.e)(version>=1.0.0))
|
export: osgi.wiring.package=b.e; uses:=a
B [33.0]
import: (&(osgi.wiring.package=a)(version>=1.0.0))
|
export: osgi.wiring.package=a
C [9.0]
I was initially surprised that b.e generates a uses clause for 'a'. This is not declared in the Manifest nor the OBR repository.xml through which these bundles are provisioned. However, types in b.e expose types in a through their API, so I guess this is where it comes from.
The only way I find to resolve these is to increase the version number of the export and import of intermediate packages, e.g. b.e in this example. However, there are a lot of packages that ultimately use 'a', transitively.
This means every time I update 'a' I also need to update all transitive dependencies on a with new versions. Is it the correct thing to be doing to increase the version number of these packages? Is refactoring my code to be less interdependent the only other way?
The uses constraints are not handled transitively by the resolver.
If bundle C imports b.e and b.e used b.d, then bundle C also needs to import b.d. That is, the public signature of b.e includes a reference to something in b.d. This is why we say b.e uses b.d. Therefore, any bundle which imports b.e must also import b.d. Otherwise the bundle cannot properly use b.e since some type referenced in b.e is not visible to the bundle.
For the export of b.e, it should state it uses b.d, b.c, b.b, b.a and a since using b.d means you also use b.c and so on...
Did you hand generate your uses clauses? Or was this example derived from something bnd generated?