Home  >  Article  >  Backend Development  >  Import files from another directory

Import files from another directory

WBOY
WBOYforward
2024-02-06 08:57:12609browse

Import files from another directory

Question content

I am trying to import utility into github_events.go.

utility.go is placed in the services directory.

utility.go looks like this:

package utility

import (
    "os"
    "regexp"
)

My project structure is as follows:

This is how to import from github_events.go

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

"github-app/services/utility"
)

I also tried using the alias utility "github-app/services/utility"

But I get the following error Unable to 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 did i do wrong?


Correct answer


Just import "github-app/services".

The above is the detailed content of Import files from another directory. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete