Start by creating a ./x/nameservice/alias.go
file. The main reason for having this file is to prevent import cycles. You can read more about import cycles in go here: Golang import cycles
First start by importing the "types" folder you have created.
package nameservice
import (
"github.com/cosmos/sdk-application-tutorial/x/nameservice/types"
)
There are three kinds of types we will create in the alias.go file.
- a constant, this is where you will define immutable variables.
const (
ModuleName = types.ModuleName
RouterKey = types.RouterKey
StoreKey = types.StoreKey
)
- a variable, which you will define to contain information such as your messages.
var (
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
NewMsgBuyName = types.NewMsgBuyName
NewMsgSetName = types.NewMsgSetName
NewMsgDeleteName = types.NewMsgDeleteName
NewWhois = types.NewWhois
RegisterCodec = types.RegisterCodec
ModuleCdc = types.ModuleCdc
)
- a type, here you will define the types you have created in the types folder.
type (
Keeper = keeper.Keeper
MsgSetName = types.MsgSetName
MsgBuyName = types.MsgBuyName
MsgDeleteName = types.MsgDeleteName
QueryResResolve = types.QueryResResolve
QueryResNames = types.QueryResNames
Whois = types.Whois
)
Now you have aliased your needed constants, variables, and types. We can move forward with the creation of the module.