Skip to content

Commit

Permalink
fix: refactor value name
Browse files Browse the repository at this point in the history
  • Loading branch information
almas1992 committed Dec 24, 2024
1 parent 9357c19 commit a3f9544
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions foundation/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func (app *Application) GetJson() foundation.Json {
return app.json
}

func (app *Application) About(section string, details []foundation.AboutInfo) {
console.AddAboutInformation(section, details...)
func (app *Application) About(section string, items []foundation.AboutItem) {
console.AddAboutInformation(section, items...)
}

func (app *Application) IsLocale(ctx context.Context, locale string) bool {
Expand Down
24 changes: 12 additions & 12 deletions foundation/console/about_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type AboutCommand struct {

type information struct {
section map[string]int
details [][]foundation.AboutInfo
details [][]foundation.AboutItem
}

var appInformation = &information{section: make(map[string]int)}
Expand Down Expand Up @@ -55,10 +55,10 @@ func (r *AboutCommand) Extend() command.Extend {
func (r *AboutCommand) Handle(ctx console.Context) error {
r.gatherApplicationInformation()
ctx.NewLine()
appInformation.Range(ctx.Option("only"), func(section string, details []foundation.AboutInfo) {
appInformation.Range(ctx.Option("only"), func(section string, items []foundation.AboutItem) {
ctx.TwoColumnDetail("<fg=green;op=bold>"+section+"</>", "")
for i := range details {
ctx.TwoColumnDetail(details[i].Key, details[i].Value)
for i := range items {
ctx.TwoColumnDetail(items[i].Key, items[i].Value)
}
ctx.NewLine()
})
Expand All @@ -68,7 +68,7 @@ func (r *AboutCommand) Handle(ctx console.Context) error {
// gatherApplicationInformation Gather information about the application.
func (r *AboutCommand) gatherApplicationInformation() {
configFacade := r.app.MakeConfig()
appInformation.addToSection("Environment", []foundation.AboutInfo{
appInformation.addToSection("Environment", []foundation.AboutItem{
{Key: "Application Name", Value: configFacade.GetString("app.name")},
{Key: "Goravel Version", Value: strings.TrimPrefix(r.app.Version(), "v")},
{Key: "Go Version", Value: strings.TrimPrefix(runtime.Version(), "go")},
Expand All @@ -84,7 +84,7 @@ func (r *AboutCommand) gatherApplicationInformation() {
{Key: "HTTP Host", Value: configFacade.GetString("http.host")},
{Key: "HTTP Port", Value: configFacade.GetString("http.port")},
})
appInformation.addToSection("Drivers", []foundation.AboutInfo{
appInformation.addToSection("Drivers", []foundation.AboutItem{
{Key: "Cache", Value: configFacade.GetString("cache.default")},
{Key: "Database", Value: configFacade.GetString("database.default")},
{Key: "Hashing", Value: configFacade.GetString("hashing.driver")},
Expand All @@ -108,18 +108,18 @@ func (r *AboutCommand) gatherApplicationInformation() {
}

// addToSection Add a new section to the application information.
func (info *information) addToSection(section string, details []foundation.AboutInfo) {
func (info *information) addToSection(section string, items []foundation.AboutItem) {
index, ok := info.section[section]
if !ok {
index = len(info.details)
info.section[section] = index
info.details = append(info.details, make([]foundation.AboutInfo, 0))
info.details = append(info.details, make([]foundation.AboutItem, 0))
}
info.details[index] = append(info.details[index], details...)
info.details[index] = append(info.details[index], items...)
}

// Range Iterate over the application information sections.
func (info *information) Range(section string, ranger func(s string, details []foundation.AboutInfo)) {
func (info *information) Range(section string, ranger func(s string, items []foundation.AboutItem)) {
var sections []string
for s := range info.section {
if len(section) == 0 || strings.EqualFold(section, s) {
Expand All @@ -138,8 +138,8 @@ func (info *information) Range(section string, ranger func(s string, details []f
}

// AddAboutInformation Add custom information to the application information.
func AddAboutInformation(section string, details ...foundation.AboutInfo) {
func AddAboutInformation(section string, items ...foundation.AboutItem) {
customInformationResolvers = append(customInformationResolvers, func() {
appInformation.addToSection(section, details)
appInformation.addToSection(section, items)
})
}
18 changes: 9 additions & 9 deletions mocks/foundation/Application.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3f9544

Please sign in to comment.