Search code examples
godesktop-applicationwails

Import package from another module


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?


Solution

  • 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 => ../../