Home > OS >  Go import file from another directory
Go import file from another directory

Time:01-20

I'm trying to import utility into github_events.go.

utility.go is placed under services directory.

utility.go looks like this:

package utility

import (
    "os"
    "regexp"
)

My project structure looks like this:

enter image description here

This is how import from github_events.go

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"sync"
"time"
"sort"

"github-app/services/utility"
)

I also tried with an alias utility "github-app/services/utility"

But I get the following error could not import github-app/services/utility (no required module provides package "github-app/services/utility")compilerBrokenImport

My go.mod file:

    module github-app
    go 1.18

What am I doing wrong?

CodePudding user response:

Just import "github-app/services" and you're good to go.

  •  Tags:  
  • go
  • Related