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

Following GETTING STARTED guide does not work #28

Open
FriesK1 opened this issue Nov 20, 2020 · 4 comments
Open

Following GETTING STARTED guide does not work #28

FriesK1 opened this issue Nov 20, 2020 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@FriesK1
Copy link

FriesK1 commented Nov 20, 2020

🚨 First, please check:

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 FriesK1 added the bug Something isn't working label Nov 20, 2020
@vaind
Copy link
Contributor

vaind commented Nov 20, 2020

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 vaind added documentation Improvements or additions to documentation and removed bug Something isn't working labels Nov 20, 2020
@FriesK1
Copy link
Author

FriesK1 commented Nov 23, 2020

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.

@vaind
Copy link
Contributor

vaind commented Nov 23, 2020

... 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).

@sgbell
Copy link

sgbell commented May 29, 2022

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.

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

No branches or pull requests

3 participants