objectbox-go icon indicating copy to clipboard operation
objectbox-go copied to clipboard

Following GETTING STARTED guide does not work

Open FriesK1 opened this issue 5 years ago • 4 comments

:rotating_light: First, please check:

  • existing issues (including closed ones),
  • Docs https://golang.objectbox.io/
  • FAQ page https://golang.objectbox.io/faq

Description

When I add the code from the getting started guide into a main.go file and run "go run main.go", I receive the following error: package command-line-arguments main.go:5:2: use of internal package github.com/objectbox/objectbox-go/examples/tasks/internal/model not allowed

Basic info

Please complete the following information:

  • ObjectBox version (are you using the latest version?): [e.g. v1.1.2] not sure how to tell,, I ran the install script, it is the version installed from there

  • GO version: go version go1.15.3 darwin/amd64

  • Reproducibility: [e.g. occurred once only | occasionally without visible pattern | always] always

  • Device: [e.g. Desktop] Desktop

  • OS: [e.g. Ubuntu 20.04] MacOS

How to reproduce

Steps to reproduce the behavior:

  1. Enter code from user guide in files specified
  2. Run go generate
  3. Run go run
  4. Receive eror

Expected behavior

This should run the sample program documented

Code

`package main

import ( "fmt" "github.com/objectbox/objectbox-go/examples/tasks/internal/model" "github.com/objectbox/objectbox-go/objectbox" )

func initObjectBox() *objectbox.ObjectBox { objectBox, _ := objectbox.NewBuilder().Model(model.ObjectBoxModel()).Build() return objectBox }

func main() { // load objectbox ob := initObjectBox() defer ob.Close() // In a server app, you would just keep ob and close on shutdown

box := model.BoxForTask(ob)

// Create id, _ := box.Put(&model.Task{ Text: "Buy milk", })

task, _ := box.Get(id) // Read task.Text += " & some bread"

fmt.Printf("My Test Record:\n") fmt.Printf("%+v", task) fmt.Printf("\n\n")

box.Put(task) // Update count, _ := box.Count() fmt.Printf("After the add, there are %d tasks in the list\n", count)

box.Remove(task) // Delete count, _ = box.Count() fmt.Printf("After the remove, there are %d tasks in the list\n", count) }`

FriesK1 avatar Nov 20 '20 21:11 FriesK1

I guess the code block in this section is the culprit, right?. We should think about how to change the imports in the docs so that it's clear user needs to actually change them to their module path...

vaind avatar Nov 20 '20 21:11 vaind

I guess the code block in this section is the culprit, right?. We should think about how to change the imports in the docs so that it's clear user needs to actually change them to their module path...

I am not sure if this is a documentation only issue or not. I was able to work around the issue by using direct paths, but this is considered extremely bad form. The code we need to include should be generated into a vendor folder and documentation should be adjusted to identify the proper path from there, and vendoring needs to be turned on during installation, creating a go dependency issue.

This is probably not simply a documentation issue if done correctly due to changes in the language.

FriesK1 avatar Nov 23 '20 14:11 FriesK1

... The code we need to include...

That's exactly the misunderstanding I think needs addressing in the docs. You don't need to include any code from "github.com/objectbox/objectbox-go/examples/tasks/internal/model" - the whole "example/tasks" folder is an example of a self-contained application. You can copy-paste it, initialize it as your own go module (picking your own name, for example, github.com/FriesK1/objectbox-playground) and replace all the imports with the module name you've chosen (e.g. github.com/FriesK1/objectbox-playground).

vaind avatar Nov 23 '20 15:11 vaind

Just to throw in my 2 cents on this.. I couldn't get the command: go generate ./... working until I tried to run the command:

go test github.com/objectbox/objectbox-go

Running that command, then informed me of the commands I need to run to get objectbox-go working:

go get github.com/objectbox/objectbox-go go get github.com/objectbox/objectbox-go/cmd/[email protected] go get github.com/objectbox/objectbox-go/examples/tasks/internal/[email protected]

After installing those packages

go generate ./...

worked, and I was able to work with the package.

I'm new to golang, and it took me a few hours of messing around, to finally give the go test command a try, as I assumed I could just jump straight in.

sgbell avatar May 29 '22 06:05 sgbell