Unable to build the app in golang with oracle db - oracle

I am a beginner in go lang development and I try to connect the cloud oracle DB from go server(using 'github.com/godror/godror' package).
I install the Oracle instant client and set the environment path also.
Go server is running and able to establish the connection and queries. But when I am building a production app got these errors.
Command: env GOOS=linux GOARCH=amd64 go build -o odb db_main.go
../github.com/godror/godror/orahlp.go:452:53: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:461:53: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:479:19: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:480:19: undefined: VersionInfo
../github.com/godror/godror/orahlp.go:481:30: undefined: ObjectType
../github.com/godror/godror/orahlp.go:482:31: undefined: Event
../github.com/godror/godror/orahlp.go:482:42: undefined: SubscriptionOption
../github.com/godror/godror/orahlp.go:482:64: undefined: Subscription
../github.com/godror/godror/orahlp.go:483:10: undefined: StartupMode
../github.com/godror/godror/orahlp.go:484:11: undefined: ShutdownMode
../github.com/godror/godror/orahlp.go:484:11: too many errors```
My server code(db_main.go)
```package main
import (
"database/sql"
"encoding/json"
"fmt"
"log"
"net/http"
"time"
_ "github.com/godror/godror"
)
// VersionInfo,ObjectType,Event,SubscriptionOption,Subscription,StartupMode,ShutdownMode
var db *sql.DB
func main() {
var err error
db, err = sql.Open("godror", "xyz/abc#13.43.11.8:1521/sampledb")
if err != nil {
log.Println("Error")
fmt.Println(err)
return
}
defer db.Close()
port := ":8000"
http.HandleFunc("/insert", InsertData)
http.HandleFunc("/list", GetList)
log.Println("Tranzo-Shahi Oracle DB running in ", port)
httpErr := http.ListenAndServe(port, nil)
if httpErr != nil {
log.Println("Tranzo-Shahi Oracle DB Error: ", httpErr.Error())
}
}

Run env GOOS=linux GOARCH=amd64 go build -o odb and don't specify any file. If you do specify one, like db_main.go then you need to specify all the files it the package that must be included in the build.

Unfortunately original question has no mentioning of where the build run. It's important to know.
godror documentation points to possible problems when you try cross-compile your code. It's in their documentation: Cgo is required, so cross-compilation is hard, and you cannot set CGO_ENABLED=0!
I would suggest to run your build on Linux machine. (Verify it has gcc installed.)
Run your build as env CGO_ENABLED=1 go build -o odb

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.

Install go scenery - cannot use &SceneryDefinition

I've got go installed. However, when I do this:
go get -u github.com/dmlittle/scenery
I get:
# github.com/dmlittle/scenery/pkg/parser
go/src/github.com/dmlittle/scenery/pkg/parser/parser.go:98:20: cannot use &SceneryDefinition literal (type *SceneryDefinition) as type lexer.Definition in argument to participle.Lexer:
*SceneryDefinition does not implement lexer.Definition (wrong type for Lex method)
have Lex(io.Reader) (lexer.Lexer, error)
want Lex(string, io.Reader) (lexer.Lexer, error)
go/src/github.com/dmlittle/scenery/pkg/parser/parser.go:116:21: not enough arguments in call to p.ParseString
have (string, *Plan)
want (string, string, interface {}, ...participle.ParseOption)
go/src/github.com/dmlittle/scenery/pkg/parser/scanner.go:39:10: undefined: lexer.Errorf
go/src/github.com/dmlittle/scenery/pkg/parser/scanner.go:82:26: undefined: lexer.Errorf
Any suggestions?
Same issue, seems the prj use dep. I've fixed cloning the repo, then configuring the go module that find the right project dependencies. Then run go get again and the build success:
~/go/src/github.com/dmlittle/scenery (master ✔) ᐅ go run main.go
# github.com/dmlittle/scenery/pkg/parser
pkg/parser/parser.go:98:20: cannot use &SceneryDefinition literal (type *SceneryDefinition) as type lexer.Definition in argument to participle.Lexer:
*SceneryDefinition does not implement lexer.Definition (wrong type for Lex method)
have Lex(io.Reader) (lexer.Lexer, error)
want Lex(string, io.Reader) (lexer.Lexer, error)
pkg/parser/parser.go:116:21: not enough arguments in call to p.ParseString
have (string, *Plan)
want (string, string, interface {}, ...participle.ParseOption)
pkg/parser/scanner.go:39:10: undefined: lexer.Errorf
pkg/parser/scanner.go:82:26: undefined: lexer.Errorf
Init go mod:
~/go/src/github.com/dmlittle/scenery (master ✔) ᐅ go mod init
go: creating new go.mod: module github.com/dmlittle/scenery
go: copying requirements from Gopkg.lock
Check dependencies:
go mod tidy
go: downloading github.com/spf13/cobra v0.0.3
go: downloading github.com/fatih/color v1.7.0
....
Install package:
go get -u github.com/dmlittle/scenery
Works as expected :
~/go/src/github.com/dmlittle/scenery (master ✘)✭ ᐅ ./scenery
Usage:
scenery [flags]
Examples:
terraform plan | scenery
Flags:
-h, --help help for scenery
-n, --no-color Print output without color
--version version for scenery

gcloud app deploy says: exec: "git": executable file not found in $PATH

I am struggling to deploy a simple Go app to Google App Engine flexible environment. (This is a very cut-down version of a larger app.) When I run gcloud app deploy --project=<projectID> it terminates with an error, and has this in its output:
...
Step #0: Status: Downloaded newer image for gcr.io/gcp-runtimes/go1-builder#sha256:68b86e4c97438df4c9e36c55ad724079b453398a0a44c29748fb5685eef73895
Step #0: gcr.io/gcp-runtimes/go1-builder#sha256:68b86e4c97438df4c9e36c55ad724079b453398a0a44c29748fb5685eef73895
Step #0: go: github.com/go-stack/stack#v1.8.0: git init --bare in /workspace/_gopath/pkg/mod/cache/vcs/6963ea18be763686e7a9697733dd92bfcc0d45b687afce82da04992523d91cd1: exec: "git": executable file not found in $PATH
Step #0: go: github.com/inconshreveable/log15#v0.0.0-20200109203555-b30bc20e4fd1: git init --bare in /workspace/_gopath/pkg/mod/cache/vcs/fe2a07d0f4107d9daa39043733e909094a5b926cca44d0f7269e7a2185dbef15: exec: "git": executable file not found in $PATH
Step #0: go: github.com/mattn/go-colorable#v0.1.6: git init --bare in /workspace/_gopath/pkg/mod/cache/vcs/f7e99db597f4d2fe3e4509a9af308dace72a13292b505deb909cd0df29c1468a: exec: "git": executable file not found in $PATH
Step #0: go: error loading module requirements
Finished Step #0
It does work if I delete go.mod, but (I think) I need go.mod to compile and test it locally. It does work if I don't import the external package, but of course I need external packages in my larger app. It does work if I choose the standard environment, but I need the flexible environment for my larger app.
How can I deploy this app successfully to a flexible environment?
My local Go is 1.13, and I have the latest version (292.0.0) of gcloud. Apart from go.sum, the contents of my directory is...
app.yaml:
runtime: go1.12
env: flex
go.mod:
module mymodulename
go 1.13
require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/inconshreveable/log15 v0.0.0-20200109203555-b30bc20e4fd1
github.com/mattn/go-colorable v0.1.6 // indirect
)
main.go:
package main
import (
"fmt"
"net/http"
"os"
"github.com/inconshreveable/log15"
)
func main() {
log := log15.New()
http.HandleFunc("/", helloHandler)
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Info("Using default port", "port", port)
}
log.Info("Listening", "port", port)
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Crit("ListenAndServe", "error", err)
os.Exit(1)
}
}
func helloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello, there")
}
Thank you.
IIUC Flexible doesn't support modules (Standard does, go figure!).
You can:
either use a custom runtime;
or, delete the go.mod|go.sum and try again.
I copied your app.yaml and main.go and it worked for me.
One change to your app.yaml:
runtime: go
env: flex
Then:
go get github.com/inconshreveable/log15
go run main.go
INFO[05-15|09:33:26] Using default port port=8080
INFO[05-15|09:33:26] Listening port=8080
and:
curl --silent http://localhost:8080
Hello, there
and:
gcloud app deploy --project=${PROJECT}
curl --silent $(\
gcloud app describe \
--project=${PROJECT} \
--format="value(defaultHostname)")
Hello, there

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

Golang failes to change the name of imported module

I'm trying to bring SkyDNSv1 back to life and build it from my fork (here is Dockerfile). SkyDNS was really good and simple tool for the quick service discovery, but it wasn't updated for a long time.
There is an error in build process and it's caused by third party library. I cannot figure out why does it happen:
$ docker build --no-cache -t skydns1 .
Sending build context to Docker daemon 1.566 MB
Sending build context to Docker daemon
Step 0 : FROM golang:1.4.2
---> 3e8cb8e0c765
Step 1 : WORKDIR /go/src
---> Running in 3a06cf460ad9
---> 1dd14a099164
Removing intermediate container 3a06cf460ad9
Step 2 : RUN go get github.com/codegangsta/cli
---> Running in eabcfd6fe621
---> c9ea222f2d74
Removing intermediate container eabcfd6fe621
Step 3 : RUN go get github.com/vitalyisaev2/skydns1
---> Running in 3264582b2e7a
# github.com/rcrowley/go-metrics/influxdb
github.com/rcrowley/go-metrics/influxdb/influxdb.go:19: undefined: client.ClientConfig
github.com/rcrowley/go-metrics/influxdb/influxdb.go:38: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:44: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:52: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:60: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:70: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:82: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:93: undefined: client.Series
github.com/rcrowley/go-metrics/influxdb/influxdb.go:106: client.WriteSeries undefined (type *client.Client has no field or method WriteSeries)
INFO[0075] The command [/bin/sh -c go get github.com/vitalyisaev2/skydns1] returned a non-zero code:
But if you look through the file causing this error, you'll notice that Golang is confused about influxdb/client. I think that compiler doesn't replace imported name client with influxClient as it should do:
package influxdb
import (
"fmt"
influxClient "github.com/influxdb/influxdb/client"
"github.com/rcrowley/go-metrics"
"log"
"time"
)
Probably I just missing an obvious mistake. Any help will be appreciated.
The Go compiler doesn't replace or rewrite anything, the code is just wrong. The github.com/rcrowley/go-metrics/influxdb package was written with some other influxdb client code that no longer exists. (Looks like there are a couple github issues open about this already)
If you look at the current influxdb/client package, you'll see there's no Series, ClientConfig, or Client.WriteSeries at all. You'll need to drop the dependency on github.com/rcrowley/go-metrics/influxdb in order to get your project to build.

Resources