-1

I have to create a desktop app on top of existing Go backend code, since this requirement and my knowledge in web development I'm using Wails.

With Wails CLI I generated the desktop app project in a subfolder of the back end main project. This is how the folder structure looks like:

backend
├── [...]
├── logger
│   └── logger.go
├── gui
│   └── desktopApp
│       ├── build
│       │   └── desktopApp
│       ├── frontend
│       │   └── [...]
│       ├── go.mod
│       ├── go.sum
│       ├── main.go
│       └── project.json
├── main.go
├── go.mod
└── go.sum

The logger has been imported in the desktopApp and everything works during the development and testing via browser. But when I build the desktop app with the command wails build from the desktopApp folder I have got the following error:

go: <domain>/<owner>/backend/logger: unrecognized import path "<domain>/<owner>/backend"

I imported the backend in the desktop app like this:

/backend/gui/desktopApp/go.mod

module desktopApp

go 1.15

require (
    <domain>/<owner>/backend v0.0.0
)

./gui/desktopApp/main.go

package main

import (
    "github.com/leaanthony/mewn"
    "github.com/wailsapp/wails"

    "<domain>/<owner>/backend/logger"
)

// Using the logger package normally

How can I fix my issue?

chenny
  • 769
  • 2
  • 17
  • 44

2 Answers2

2

I see that you use go-module and store code in a repo with sub-module

The problem is that you forgot add "desktopApp"-prefix

import (
    "github.com/leaanthony/mewn"
    "github.com/wailsapp/wails"

    "desktopApp/backend/backendPackage"
)

Right way use modules

Fix go.mod of desktopApp module

module <domain>/<owner>/desktopApp

go 1.15

fix backends import , because it belongs to desktopApp

import (
    "github.com/leaanthony/mewn"
    "github.com/wailsapp/wails"

    "<domain>/<owner>/desktopApp/backend/backendPackage"
)
kozmo
  • 4,024
  • 3
  • 30
  • 48
  • I edited the question because probably it was not clear. `backend` is the existing repo and I created the `desktopApp` as sub-module. Anyway I'm trying to fix it with your hint. – chenny Sep 30 '20 at 11:19
0

I solved my issue changing go.mod file of the nested desktop app like this:

module desktopApp

go 1.15

require (
    <domain>/<owner>/backend/logger
)
// Added this line
replace <domain>/<owner>/backend/logger => ../../
chenny
  • 769
  • 2
  • 17
  • 44