Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot install using go 1.18.1 #25

Closed
gurugeek opened this issue Apr 17, 2022 · 29 comments
Closed

cannot install using go 1.18.1 #25

gurugeek opened this issue Apr 17, 2022 · 29 comments

Comments

@gurugeek
Copy link

It seems that the package id not running perhaps for a breaking change on the UUID package

 go get github.com/ostafen/clover
# github.com/ostafen/clover
../../../go/src/github.com/ostafen/clover/db.go:49:9: multiple-value uuid.NewV4() (value of type (uuid.UUID, error)) in single-value context
@ostafen
Copy link
Owner

ostafen commented Apr 17, 2022

Hi, I have Go 1.18.0 and all is working fine.
I'll try to update to 1.18.1 to reproduce the issue.
I'll let you know as soon as possible.
However, looking at the output, it seems like you already had a different version of the uuid library. Can you check this?

@gurugeek
Copy link
Author

@ostafen thanks for your prompt reply. I didn't have a different version of UUID. I just removed and it and it installed again satori/go.uuid

@ostafen
Copy link
Owner

ostafen commented Apr 17, 2022

Is the version you are getting installed v1.2.0?

@ASWLaunchs
Copy link
Contributor

ASWLaunchs commented Apr 17, 2022

It seems that the package id not running perhaps for a breaking change on the UUID package

I am using go 1.18.0 which is perfectly supported. I haven't tried to test on 1.18.1 yet
image

@gurugeek
Copy link
Author

Is the version you are getting installed v1.2.0?

yes it is the default one required in your .mod package. I also tried to delete it and run again the go get go get github.com/ostafen/clover but I get the same error.

I am using Mac OS X I can try to downgrade to go 1.18.0 but it seems that by default the go.dev sites only proposes the 1.18.1

@ostafen
Copy link
Owner

ostafen commented Apr 17, 2022

The thing which looks quite strange to me is that, according to the error, it seems that the API returns 2 values, instead of one. This could only be due to a different version of the uuid package being installed.
I will lwt you know as soon as I try the 1.18.1

@gurugeek
Copy link
Author

@ostafen thanks a lot much appreciated. I will also try to downgrade to see if the error persists.

@gurugeek
Copy link
Author

gurugeek commented Apr 17, 2022

@ostafen no luck with go 1.18


go version go1.18 darwin/arm64
gurugeek@Davids-iMac go-experiments %   go get github.com/ostafen/clover
# github.com/ostafen/clover
../../../go/src/github.com/ostafen/clover/db.go:49:9: multiple-value uuid.NewV4() (value of type (uuid.UUID, error)) in single-value context
gurugeek@Davids-iMac go-experiments % 

I deleted the previous packages before attempting to reinstall

@ostafen
Copy link
Owner

ostafen commented Apr 17, 2022

Can you give the output of the following command?

go list -m all | grep github.com/satori/go.uuid

I think that the error is not related with the go version

@ostafen
Copy link
Owner

ostafen commented Apr 17, 2022

try to delete the module and execute this:

GO111MODULE=on go get github.com/satori/go.uuid@063359185d32c6b045fa171ad7033ea545864fa1

@gurugeek
Copy link
Author

go list -m all | grep github.com/satori/go.uuid

github.com/satori/go.uuid v1.2.0

@gurugeek
Copy link
Author

gurugeek commented Apr 17, 2022

gurugeek@Davids-iMac clover % GO111MODULE=on go get github.com/satori/go.uuid@063359185d32c6b045fa171ad7033ea545864fa1
go: downloading github.com/satori/go.uuid v1.1.1-0.20180103003558-063359185d32
go: downgraded github.com/satori/go.uuid v1.2.0 => v1.1.1-0.20180103003558-063359185d32

but back to my directory when I try the example I now get this error with GO111MODULE=on

 go run main.go                       
main.go:4:2: no required module provides package github.com/ostafen/clover: go.mod file not found in current directory or any parent directory; see 'go help modules'

my main.go is


package main
import (
	"log"
	c "github.com/ostafen/clover"
)

db, _ := c.Open("clover-db")
db.CreateCollection("myCollection") // create a new collection named "myCollection"

// insert a new document inside the collection
doc := c.NewDocument()
doc.Set("hello", "clover!")

// InsertOne returns the id of the inserted document
docId, _ := db.InsertOne("myCollection", doc)
fmt.Println(docId)

it seems to be related to mysystem using GO111MODULE=off.
which returns

gurugeek@Davids-iMac go-experiments % go get github.com/satori/go.uuid
gurugeek@Davids-iMac go-experiments % go run main.go

github.com/ostafen/clover

../../../go/src/github.com/ostafen/clover/db.go:49:9: multiple-value uuid.NewV4() (value of type (uuid.UUID, error)) in single-value context
gurugeek@Davids-iMac go-experiments %

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

it seems to be related to mysystem using GO111MODULE=off.

So did you fix?

I also checked the version which is installed on my system.

If I run the go list command, I also get the output: github.com/satori/go.uuid v1.2.0.
So the version which you get installed is the same (as a matter of facts the v1.2.0 tags a specific commit, so there should be no way, at least in theory you get a different commit).

You could try to check inside the code of the github.com/satori/go.uuid code, in your pkg folder.
According to your error, the NewV4 function returns two values. It is defined inside the generator.go file.
If I check my file, I see the following:

// NewV4 returns random generated UUID.
func NewV4() UUID {
return global.NewV4()
}

Check if it is true that you have a different version of the function, returning two values (as the error message seems to suggest).

@gurugeek
Copy link
Author

gurugeek commented Apr 18, 2022

No, I didn't fix it.

Just to clarify I am installing clover as per readme with the go get command and not with go install.

So I removed it, ncluding the UUID package, and I get:


gurugeek@Davids-iMac go-experiments %   go get github.com/ostafen/clover
# github.com/ostafen/clover
../../../go/src/github.com/ostafen/clover/db.go:49:9: multiple-value uuid.NewV4() (value of type (uuid.UUID, error)) in single-value context
gurugeek@Davids-iMac go-experiments % 



inside db.go on line 49 I have a different code:

func newObjectId() string {
	return uuid.NewV4().String()
}

perhaps go get fetches a different version ?

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

inside db.go on line 49 I have a different code:

That snippet is inside clover. It is fine. The problem is with the NewV4() method, which, in your case seems to return 2 values instead of one. You have to check the definition of the uuid.NewV4() function inside the code of your uuid package being fetched by go get.
If you use VSCode or Goland, you should be able to jump to the definition of the function by typing Ctrl+Click on the NewV4() function (alternatively, you can find the source code of the uuid module inside your pkg folder)

@gurugeek
Copy link
Author

this is the code inside uuid.go as fetched by go get once I fetch clover:


// Copyright (C) 2013-2018 by Maxim Bublis <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// Package uuid provides implementation of Universally Unique Identifier (UUID).
// Supported versions are 1, 3, 4 and 5 (as specified in RFC 4122) and
// version 2 (as specified in DCE 1.1).
package uuid

import (
	"bytes"
	"encoding/hex"
)

// Size of a UUID in bytes.
const Size = 16

// UUID representation compliant with specification
// described in RFC 4122.
type UUID [Size]byte

// UUID versions
const (
	_ byte = iota
	V1
	V2
	V3
	V4
	V5
)

// UUID layout variants.
const (
	VariantNCS byte = iota
	VariantRFC4122
	VariantMicrosoft
	VariantFuture
)

// UUID DCE domains.
const (
	DomainPerson = iota
	DomainGroup
	DomainOrg
)

// String parse helpers.
var (
	urnPrefix  = []byte("urn:uuid:")
	byteGroups = []int{8, 4, 4, 4, 12}
)

// Nil is special form of UUID that is specified to have all
// 128 bits set to zero.
var Nil = UUID{}

// Predefined namespace UUIDs.
var (
	NamespaceDNS  = Must(FromString("6ba7b810-9dad-11d1-80b4-00c04fd430c8"))
	NamespaceURL  = Must(FromString("6ba7b811-9dad-11d1-80b4-00c04fd430c8"))
	NamespaceOID  = Must(FromString("6ba7b812-9dad-11d1-80b4-00c04fd430c8"))
	NamespaceX500 = Must(FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
)

// Equal returns true if u1 and u2 equals, otherwise returns false.
func Equal(u1 UUID, u2 UUID) bool {
	return bytes.Equal(u1[:], u2[:])
}

// Version returns algorithm version used to generate UUID.
func (u UUID) Version() byte {
	return u[6] >> 4
}

// Variant returns UUID layout variant.
func (u UUID) Variant() byte {
	switch {
	case (u[8] >> 7) == 0x00:
		return VariantNCS
	case (u[8] >> 6) == 0x02:
		return VariantRFC4122
	case (u[8] >> 5) == 0x06:
		return VariantMicrosoft
	case (u[8] >> 5) == 0x07:
		fallthrough
	default:
		return VariantFuture
	}
}

// Bytes returns bytes slice representation of UUID.
func (u UUID) Bytes() []byte {
	return u[:]
}

// Returns canonical string representation of UUID:
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
func (u UUID) String() string {
	buf := make([]byte, 36)

	hex.Encode(buf[0:8], u[0:4])
	buf[8] = '-'
	hex.Encode(buf[9:13], u[4:6])
	buf[13] = '-'
	hex.Encode(buf[14:18], u[6:8])
	buf[18] = '-'
	hex.Encode(buf[19:23], u[8:10])
	buf[23] = '-'
	hex.Encode(buf[24:], u[10:])

	return string(buf)
}

// SetVersion sets version bits.
func (u *UUID) SetVersion(v byte) {
	u[6] = (u[6] & 0x0f) | (v << 4)
}

// SetVariant sets variant bits.
func (u *UUID) SetVariant(v byte) {
	switch v {
	case VariantNCS:
		u[8] = (u[8]&(0xff>>1) | (0x00 << 7))
	case VariantRFC4122:
		u[8] = (u[8]&(0xff>>2) | (0x02 << 6))
	case VariantMicrosoft:
		u[8] = (u[8]&(0xff>>3) | (0x06 << 5))
	case VariantFuture:
		fallthrough
	default:
		u[8] = (u[8]&(0xff>>3) | (0x07 << 5))
	}
}

// Must is a helper that wraps a call to a function returning (UUID, error)
// and panics if the error is non-nil. It is intended for use in variable
// initializations such as
//	var packageUUID = uuid.Must(uuid.FromString("123e4567-e89b-12d3-a456-426655440000"));
func Must(u UUID, err error) UUID {
	if err != nil {
		panic(err)
	}
	return u
}

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

This file doesn't contain the definition of the NewV4() function. It should be contained in the generator.go file

@gurugeek
Copy link
Author

here it is

// NewV4 returns random generated UUID.
func NewV4() (UUID, error) {
	return global.NewV4()
}

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

Ok, this is the proof you are getting a different version of the library (if you look at the one I posted, there is a mismatch in the number of returned values).
As a quick fix, you could modify the clover db.go file to get rid of the additional error parameter being returned by NewV4.
However, we need to understand what is going on, and why.
First of all, we need to understand the exact commit of the library which is fetched by go get

@gurugeek
Copy link
Author

@ostafen thanks a lot for your quick comments. Just to clarify the version fetched by go get is exactly the version available in github
https://github.com/satori/go.uuid/blob/master/generator.go
line 67 to 70 are the same.

The go mod for clover specifies 1.2.0 as a version so I think go get does fetch what is asked.
if you need a special version commit for clover to function why not fork this UUID module to ensure consistency? It has not been updated in 4 years so either is finished or unmainteined at this point :)

I assume that most of the users use go install ? With go get is definitely not working even on go 1.15 I just tried in a completely different, clean server

gurugeek@david:~$ go version
go version go1.15.15 linux/amd64
gurugeek@david:~$ go get github.com/ostafen/clover
# github.com/ostafen/clover
go/src/github.com/ostafen/clover/db.go:49:19: multiple-value uuid.NewV4() in single-value context
gurugeek@david:~$ 

Happy to help debugging if needed.

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

if you need a special version commit for clover to function why not fork this UUID module to ensure consistency

The problem here is not that clover depends on a specific commit, because as you can see, the version specified is v1. 2.0 (in fact several user using clover didn't have this problem).

If the version you get is the same which in github is tagged as v1.2.0, we have to understand why other user (me included) get an older version instead of the correct one.
Once understood this, if necessary I could fix this inside clover itself by ignoring the additional parameter returned by the NewV4 function.

I will do further tests, trying to clean my module cache and use go get

In every case, googling a bit, other people had this issue, too, using uuid.
It seems that at some point they changed the NewV4() api, and probably moved the v1.2.0 tag

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

In understood what it's going on by reading this satori/go.uuid#106.
You are probably looking the master branch of the repository. If you select the v1.2.0 tag, you will see that the source code is the same of the one I'm getting: https://github.com/satori/go.uuid/tree/v1.2.0
The problem is related to the fact that you didn't have go modules enables.
Without GOMODULES enables, by default go get fetches the last commit, thus ignoring the go.mod file.

Try to:

  • clean your module cache
  • enable GOMODULES
  • run your main.go code containing code using clover

Dependencies should be automatically fetched when you run the main.go file

@gurugeek
Copy link
Author

Thank you @ostafen but I don't wish to use GOMODULES as I have a lot of legacy code working fine with go get. If this is a pre-requisite to use Clover, I suggest you change the readme because go get will definitely not work.

As a side note/suggestion as this package appears to be a crucial dependency in clover and there is a mismatch between main and the version you want to use, it might be worth consider forking it then it will work fine.

I am slowing moving back to go after a lot of NPM dependencies issues in node so I also tend to stay away from anything that depends on something unmaintained to run.

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

Wait, it's improper to say that clover doesn't work with go get.
You only have to know that, if you use go modules, go get will fetch the exact version by looking at the go.mod file of the package automatically, and this holds for any library.
Otherwise, you have to manually specify the correct version yourself.
So this problem is not caused by clover, but by the default behavior of the go get command (when used without go.mod)

You could also enable GOMODULES on the fly only while fetching a particular library.
Try this command after cleaning up your module cache:

GOMODULE111=on go get github.com/ostafen/clover

If this works for you, I will update the README with this command

@gurugeek
Copy link
Author

@ostafen sorry I didn't meant to criticize your work, just trying to give the prospective of someone trying to install using the command on the readme. Unfortunately the last options doesn't work


on mac os x go 1.18

 GOMODULE111=on go get github.com/ostafen/clover
# github.com/ostafen/clover
../../../go/src/github.com/ostafen/clover/db.go:49:9: multiple-value uuid.NewV4() (value of type (uuid.UUID, error)) in single-value context
gurugeek@Davids-iMac go-experiments % 

on linux go 1.15

gurugeek@david:~$ GOMODULE111=on go get github.com/ostafen/clover
# github.com/ostafen/clover
go/src/github.com/ostafen/clover/db.go:49:19: multiple-value uuid.NewV4() in single-value context

strange!

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

Sorry, I made a mistake in writing the environment variable. I wrote GOMODULE111 instead of GO111MODULE.
The command should be (remember to clean the module-cache):

GO111MODULE=on go get github.com/ostafen/clover

@ostafen sorry I didn't meant to criticize your work, just trying to give the prospective of someone trying to install using the command on the readme.

Don't worry, I was just trying to explain that it's all about instructing go get properly.

@gurugeek
Copy link
Author

@ostafen thanks again for your support. Allright that works in principle but:

GO111MODULE=on go get github.com/ostafen/clover
go: go.mod file not found in current directory or any parent directory.
	'go get' is no longer supported outside a module.
	To build and install a command, use 'go install' with a version,
	like 'go install example.com/cmd@latest'
	For more information, see https://golang.org/doc/go-get-install-deprecation
	or run 'go help get' or 'go help install'.

so I had to create a mod.go file and then this code:


package main
import (
	"fmt"
	c "github.com/ostafen/clover"
)


func main() {

db, _ := c.Open("clover-db")
db.CreateCollection("myCollection") // create a new collection named "myCollection"

// insert a new document inside the collection
doc := c.NewDocument()
doc.Set("hello", "clover!")

// InsertOne returns the id of the inserted document
docId, _ := db.InsertOne("myCollection", doc)
fmt.Println(docId)

}

eventually works

 go run main.go
56a1c05e-6619-47f9-a532-74a33803062e

I am sure it is certainly my fault for not being used to the go mod system (in previous versions it didn't exist) but perhaps an example folder with a sample mod file and runnable script will be of help to go newbies :) Thanks again, this is solved now.

@ostafen
Copy link
Owner

ostafen commented Apr 18, 2022

Well! Code samples are planned.
Also, I will update the README with more detailed instructions about go get

@gurugeek
Copy link
Author

thank you @ostafen much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants