error adding golang cobra package with glide - go

My glide.yaml import section is
import:
- package: github.com/spf13/cobra
I have
import (
"github.com/spf13/cobra"
)
in my code.
but I am getting the error
vendor/github.com/spf13/cobra/command.go:1092: c.lflags.SortFlags undefined (type *pflag.FlagSet has no field or method SortFlags)
vendor/github.com/spf13/cobra/command.go:1092: c.Flags().SortFlags undefined (type *pflag.FlagSet has no field or method SortFlags)
vendor/github.com/spf13/cobra/command.go:1240: c.parentsPflags.SortFlags undefined (type *pflag.FlagSet has no field or method SortFlags)
couples of issues on cobra repo says that can happen if pflag package is old version but in my case don't have that package installed separately.
any idea what am I doing wrong? thanks in advance!

It was problem with glide cache not updating why old version of pflag package was getting installed. More detailed info: https://github.com/spf13/cobra/issues/420

Related

golang build at /vendor/github.com/weaveworks/promrus is giving an error: undefined: logrus.Level

I am trying to build the golang package (/vendor/github.com/weaveworks/promrus) in IBM Z (Mainframe). And I am getting an error: ./promrus.go:15:25: undefined: logrus.Level
My go version is: go version go1.16.2 zos/s390x
I have tried to read through the article: https://www.ibm.com/docs/en/sdk-go-zos/1.16?topic=porting-applications-zos
and have added a build constraint (//+build zos) as given below. But still the undefined error is not going away. Is there any way to build? Pls help and thanks in advance.
//+build zos
package promrus
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus" )
// PrometheusHook exposes Prometheus counters for each of logrus' log
levels. type PrometheusHook struct {
counterVec *prometheus.CounterVec }
User opened up an official support Case with IBM and found resolution.

unable to get hashicorp / vault

I need to use kmac Hashicorp's Vault implementation. However, when I run the code, the following simple import:
import (
"encoding/hex"
"fmt"
"github.com/hashicorp/vault/sdk/helper/kmac"
)
throws this error: no required module provides package github.com/hashicorp/vault/sdk/helper/kmac/kmac; to add it: go get github.com/hashicorp/vault/sdk/helper/kmac/kmac
If I run:
go get github.com/hashicorp/vault/sdk/helper/kmac/kmac
I get:
go get: module github.com/hashicorp/vault/sdk#upgrade found (v0.2.0), but does not contain package github.com/hashicorp/vault/sdk/helper/kmac/kmac
I also tested to download the latest version but I get the same error. Can I get help?

Having issue defining go_remote_library declaration for 3rdparty/go/golang.org/x/text:*

I'm trying to used github.com/spf13/viper which requires github.com/spf13/afero and that requires some of the 3rdparty/go/golang.org/x/text: packages. Till afero works, and when defining 3rdparty BUILD for text:* packages I get the following errors,
3rdparty/go/github.com/spf13/afero has remote dependencies which require local declaration:
--> golang.org/x/text/unicode/norm (expected go_remote_library declaration at 3rdparty/go/golang.org/x/text:unicode/norm)
--> golang.org/x/text/transform (expected go_remote_library declaration at 3rdparty/go/golang.org/x/text:transform)
I tried to define it like this in 3rdparty/go/golang.org/x/text/BUILD,
go_remote_library(
rev='342b2e1fbaa52c93f31447ad2c6abc048c63e475',
packages=[
'unicode/norm',
'transform',
]
)
And it still shows the same error. Plus now running buildgen.go fails with the following error,
Exception caught: (pants.build_graph.target.UnknownArgumentError) (backtrace omitted)
Exception message: Invalid target 3rdparty/go/golang.org/x/text:text: GoRemoteLibrary received unknown arguments:
packages = ['unicode/norm', 'transform']
Some more info,
- Pants version: 1.13.0
- pantsbuild.pants.contrib.go: 1.13.0
- Tried using 1.14.0 & 1.15.0 as well and got the same results
Simple example to recreate it,
package main
import (
"fmt"
"github.com/spf13/viper"
)
func main() {
viper.AutomaticEnv()
fmt.Printf("%s", viper.GetString("HOME"))
}
Also you can simply do pants resolve on the package to get the error,
pants resolve 3rdparty/go/github.com/spf13/viper
Thanks to the pants team, got the issue resolved.
buildgen.go does turn go_remote_library(pkg='foo') takes into go_remote_libraries targets.
We need to use go_remote_libraries (not go_remote_library) to specify multiple packages.
Using this works fine,
go_remote_libraries(
rev='342b2e1fbaa52c93f31447ad2c6abc048c63e475',
packages=[
'transform',
'unicode/norm',
]
)

Error when instantiate chaincode

Please help me this issue, error happened when I instantiate my chaincode:
Currently, I guess the issue related to shim package, because I remove it in my utils package, instantiate successfully.
MyChainCode:
import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/protos/msp"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/myproj/models"
"github.com/myproj/packages/utils"
)
APIstub shim.ChaincodeStubInterface
...
username, _ = utils.GetCurrentUser(APIstub)
...
My packages
package utils
import (
"github.com/hyperledger/fabric/core/chaincode/shim"
"golang.org/x/crypto/bcrypt"
)
func GetCurrentUser(stub shim.ChaincodeStubInterface) (string, error) {
cert, err := GetCreatorCert(stub)
return cert.Subject.CommonName, err
}
Issue:
Error: Error endorsing chaincode: rpc error: code = Unknown desc =
error starting container: Failed to generate platform-specific docker
build: Error returned from build: 2 "#
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:364:5:
hdr.Format undefined (type *tar.Header has no field or method Format)
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:364:15:
undefined: tar.FormatPAX
~/vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:1166:7:
hdr.Format undefined (type *tar.Header has no field or method Format)
~/vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:1166:17:
undefined: tar.FormatPAX
Fabric ver 1.1.0
Go ver 1.9.2
I faced the same problem after upgrading fabric to 1.2.0. Fabric 1.2.0 requires go 1.10.x. So I upgraded go lang to 1.10.3 and it worked like a charm.
That can be because you have old version in some files inside your hyperledger/fabric folder.
If you are following the chaincode tutorial, you can just remove your hyperledger/fabric folder.
Regards
I had the same issue by following the documentation.
Switching to branch 'release-1.1' solves the issue.
After cloning the repository proceed with:
hyperleger$ cd fabric
hyperledger/fabric$ git fetch
hyperledger/fabric$ git checkout release-1.1

Recieving following error

I am recieving an error while compilation.
Root cause is the file has import of context package, but however during compilation github.com/docker/docker/vendor/golang.org/x/net/context is getting referred a, any pointers on as how to make it to refer to context import instead of docker's vendor package
Summarizing the issue,
import in the file is as follows
import "golang.org/x/net/context"
there is a method call which takes context object as an argument, however, there are two repositories which have context ,
golang.org/x/net/context
github.com/docker/docker/vendor/golang.org/x/net/context
During compilation based on length go is selecting the 2 repository. But method needs the 1st one golang.org/x/net/context. hence the type error in code snippet is recieved
"-X main.version=dev-49-gc8cc01b -X main.commit=c8cc01b -X main.branch=master" ./...
github.com/influxdata/telegraf/plugins/inputs/docker
plugins/inputs/docker/docker.go:103: cannot use c (type *client.Client) as type DockerClient in assignment:
*client.Client does not implement DockerClient (wrong type for ContainerList method)
have ContainerList("github.com/docker/docker/vendor/golang.org/x/net/context".Context, types.ContainerListOptions) ([]types.Container, error)
want ContainerList("context".Context, types.ContainerListOptions) ([]types.Container, error) make: *** [build] Error 2 sh-4.2# vi plugins/inputs/docker/docker.go
Two options I can think of:
Add an alias for the context import, e.g.
goContext golang.org/x/net/context
docContext github.com/docker/docker/vendor/golang.org/x/net/context
Break the context dependencies into two files, or packages

Resources