Hey there,
I really like the idea and it seems like it is a good implementation. I really would like to get this to work, so I am trying my best but it is really hard to follow. Especially when the example in the folder doesn't match up at all to the examples in the instructions on the readme. I can't put two and two together to figure out what part of the example is what part of the instructions. I don't know which of the things I am supposed to create vs what running the command is supposed to create, or which thing that I have created I am supposed to actually run the command against.
If it were at all possible to try and make the written instructions match up to the actual example, that would be much more helpful. It feels like I watched and studied a training video on how to operate a machine, but then when you get to it, someone changed the location as well as the labels of all of the controls.
Perhaps you might be able to take a look at what I currently have and give me some pointers in implementation?
I have a main/appconfig
package which has a struct mapped using this config package, which is, of course, the important data that I am trying to be able to pass around throughout my application.
Which looks like the following
package appconfig
import (
"github.com/gookit/config/v2"
"github.com/gookit/config/v2/yaml"
)
type ConfigData struct {
MainSettings MainSettings
}
type ConnectionType int
const (
Oauth ConnectionType = 0
Oauth2 ConnectionType = 1
JWT ConnectionType = 2
)
type WordPressSettings struct {
ConnectionType int
ConnectionDetails struct {
SiteAddress string `json:"site_address"`
ClientId string `json:"client_id"`
ClientSecret string `json:"client_secret"`
Redirect string `json:"redirect"`
AppName string `json:"app_name"`
AccessUrl string `json:"access_url"`
AuthorizeUrl string `json:"authorize_url"`
GrantType string `json:"grant_type"`
}
Assets map[string]string `json:"assets"`
}
type MainSettings struct {
System struct {
Token string `json:"token"`
CommandPrefix string `json:"commandprefix"`
RequireEmail string `json:"requireemail"`
ConsoleLogLevel string `json:"consoleloglevel"`
FileLogLevel string `json:"fileloglevel"`
} `json:"system"`
Integrations struct {
WordPress string `json:"wordpress"`
Connection string `json:"connection"`
WebAddress string `json:"webaddress"`
} `json:"integrations"`
Discord struct {
Guild string `json:"guild"`
BotUsers []string `json:"botusers"`
Roles map[string]string `json:"roles"`
} `json:"discord"`
Assets struct {
DateCompare string `json:"datecompare"`
CompareDate string `json:"comparedate"`
AssetOriginal string `json:"assetoriginal"`
AssetReplacement string `json:"assetreplacement"`
ApiKeys map[string]string `json:"apikey"`
Packages map[string]string `json:"package"`
} `json:"assets"`
}
func (m *MainSettings) GetConfig() *MainSettings {
return m.LoadConfig()
}
func (m *MainSettings) LoadConfig() *MainSettings {
config.AddDriver(yaml.Driver)
filename := "./appconfig/config.yml"
err := config.LoadFiles(string(filename))
if err != nil {
panic(err)
}
mainSettings := &MainSettings{
System: struct {
Token string `json:"token"`
CommandPrefix string `json:"commandprefix"`
RequireEmail string `json:"requireemail"`
ConsoleLogLevel string `json:"consoleloglevel"`
FileLogLevel string `json:"fileloglevel"`
}{
Token: config.String("settings.system.token"),
CommandPrefix: config.String("settings.system.commandprefix"),
RequireEmail: config.String("settings.system.requireemail"),
ConsoleLogLevel: config.String("settings.system.consoleloglevel"),
FileLogLevel: config.String("settings.system.fileloglevel"),
},
Integrations: struct {
WordPress string `json:"wordpress"`
Connection string `json:"connection"`
WebAddress string `json:"webaddress"`
}{
WordPress: config.String("settings.integrations.wordpress"),
Connection: config.String("settings.integrations.connection"),
WebAddress: config.String("settings.integrations.webaddress"),
},
Discord: struct {
Guild string `json:"guild"`
BotUsers []string `json:"botusers"`
Roles map[string]string `json:"roles"`
}{
Guild: config.String("settings.discord.guild"),
BotUsers: config.Strings("settings.discord.botusers"),
Roles: config.StringMap("settings.discord.roles"),
},
Assets: struct {
DateCompare string `json:"datecompare"`
CompareDate string `json:"comparedate"`
AssetOriginal string `json:"assetoriginal"`
AssetReplacement string `json:"assetreplacement"`
ApiKeys map[string]string `json:"apikey"`
Packages map[string]string `json:"package"`
}{
DateCompare: config.String("settings.assets.datecompare"),
CompareDate: config.String("settings.assets.comparedate"),
AssetOriginal: config.String("settings.assets.assetoriginal"),
AssetReplacement: config.String("settings.assets.assetreplacement"),
ApiKeys: config.StringMap("settings.assets.apikey"),
Packages: config.StringMap("settings.assets.package"),
}}
return mainSettings
}
Ultimately I am trying to get that data above into this handler which gets registered on the start of the bot firing up.
func (p *ListRoles) Handle(ctx *exrouter.Context)
type ListRoles struct {
}
func (p *ListRoles) Handle(ctx *exrouter.Context) {
guildRoles, err := ctx.Ses.GuildRoles(X) // <--- Need to get the data here
if err != nil {
log.Print("Could not get list of current roles", err)
}
roleTable := p.renderMarkDownTable(guildRoles)
_, err = ctx.Reply(roleTable)
if err != nil {
log.Print("Something went wrong when handling listroles request", err)
}
// ...so on and so forth
}
func (p *ListRoles) GetCommand() string {
return listrolesRoute
}
func (p *ListRoles) GetDescription() string {
return listrolesDescription
}
func NewListRoles() *ListRoles {
return &ListRoles{}
}
My package main
of course kicks it all off:
type AppContext struct {
Verifier *verifier.Verifier
Config *appconfig.MainSettings
}
func main() {
var appContext AppContext
config := appContext.Config.GetConfig()
verifierRun, err := appContext.Verifier.VerifierRun(config))
if err != nil {
log.Println("error creating Bot session,", err)
}
defer verifierRun.Close()
err = verifierRun.Start()
if err != nil {
log.Printf("Couldn't start verifierRun: %v", err)
return
}
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
}
I am not sure if the context of the application and what I am trying to achieve makes sense. Essentially taking that MainSettings
data from the first code section and trying to get it into the func (p *ListRoles) Handle(ctx *exrouter.Context)
function. Might you be able to point me in the right direction as to which parts of my application correspond to which parts of your instructions / example? If I can try and at least map the two together, it might make it a bit more likely I will be able to get something implemented, which hopefully I will be able to do. : D
I definitely appreciate the time and effort you put into this package, I hopefully just need some clarification on things
Thanks,
-MH