Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Question: properly embedding assets when main in cmd/app #133

Open
rugwirobaker opened this issue Nov 16, 2020 · 1 comment
Open

Question: properly embedding assets when main in cmd/app #133

rugwirobaker opened this issue Nov 16, 2020 · 1 comment

Comments

@rugwirobaker
Copy link

rugwirobaker commented Nov 16, 2020

I have roughly the following structure on my project:

├── bin
│   └── blog
├── cmd
│   ├── doc.go
│   └── blog
│       └── main.go
├── dist
│   ├── css
│   │   ├── vendor~app~0027fd97.ad0a4c52.css
│   │   └── <sniped ....>
│   ├── favicon.ico
│   ├── img
│       └── app.png
│   ├── index.html
│   └── js
│        ├── app.d041f130.js
│        └── <sniped...>
├── doc.go
├── go.mod
├── go.sum
├── Makefile
└── pkged.go

pkged.go is at the root of the module and from cmd/blog/main.go I am calling pkger.Dir(/dist) which I pass to a custom filesystem http handler. It works perfectly when I run the binary ./bin/blog from this module/package but if I move it somewhere else like my home directory everything breaks apart.

This is the error I'm getting when I try to visit localhost:8080:

exit status 1: go: cannot find main module; see 'go help modules'

I have tried all kinds of workarounds including pkger -o cmd/blog but nothing seems to work. What is the proper way to do this, does it revolve around relative paths absolute paths like "github.com/my_name/my_project:dist"

@phanirithvij
Copy link

You can run pkger list and see "github.com/my_name/my_project:/dist" => pkger uses absolute imports, but relative to your go.mod file.

Can you post a reproducible code (zip maybe)? I was unable to reproduce it with your directory structure.

How do you use go build? I did

mkdir bin
pkger -o cmd/blog
go build -o bin/ ./cmd/blog
./bin/blog

cmdex.zip

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

No branches or pull requests

2 participants