Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug.List #9148

Open
bep opened this issue Nov 9, 2021 · 7 comments · May be fixed by #10806
Open

Add debug.List #9148

bep opened this issue Nov 9, 2021 · 7 comments · May be fixed by #10806

Comments

@bep
Copy link
Member

bep commented Nov 9, 2021

See https://discourse.gohugo.io/t/advice-on-how-to-inspect-a-page-context/35504/4

I suggest we add a debug.List method that uses reflection to list all fields and method names on structs/pointers, or all keys if it's a map -- non-recursive; returning a string slice would be good, I think (it prints nicely).

@bep bep self-assigned this Nov 10, 2021
@bep bep added this to the v0.90 milestone Nov 10, 2021
@bep bep removed their assignment Nov 10, 2021
@mohsalsaleem
Copy link

Hello @bep, lets assume the following is the struct

type Address {
    street string
    city     string
}
type User struct {
    name string
    address Address  
}

Then, is name, address the expected output? Or, should it get the output recursively, in this case the fields of address as well?

@bep
Copy link
Member Author

bep commented Nov 10, 2021

@mohsalsaleem to be more precise:

type Address {
    Street string
    City     string
}
type User struct {
    Name string
    Address Address
    foo     string
}

func (u *User) M1() string
func (u *User) M3() string
func (u *User) M2(v string) string
func (u *User) m4(v string) string

For User, the expected output (I think) is:

["Address", "Name", "M1", "M2", "M3"]

As in, only the exported fields and methods.

The above would some less than useful entries for the end user, but so be it.

For maps list just the keys sorted (again, non-recursive).

@mohsalsaleem
Copy link

mohsalsaleem commented Nov 10, 2021

Thanks for the explanation @bep.
I've implemented the changes in the commit mohsalsaleem@2994a16
Can you please help me with writing tests?
I see that, in tpl/debug/init.go, an example needs to be added, but I'm a bit lost as to how I can structure the example.

@bep bep modified the milestones: v0.90, v0.91.0 Dec 8, 2021
@bep bep modified the milestones: v0.91.0, v0.92.0 Dec 20, 2021
@bep bep modified the milestones: v0.92.0, v0.93.0 Jan 12, 2022
@bep bep modified the milestones: v0.93.0, v0.94.0 Mar 1, 2022
@bep bep modified the milestones: v0.94.0, v0.95.0, v0.96.0 Mar 9, 2022
@bep bep modified the milestones: v0.96.0, v0.97.0 Mar 24, 2022
@bep bep modified the milestones: v0.97.0, v0.98.0 Apr 13, 2022
@bep bep modified the milestones: v0.98.0, v0.99.0 Apr 28, 2022
@bep bep modified the milestones: v0.99.0, v0.100.0 May 24, 2022
@johannesengl johannesengl linked a pull request Mar 13, 2023 that will close this issue
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@bep bep modified the milestones: v0.113.0, v0.115.0 Jun 13, 2023
@shubmjagtap
Copy link

Hello @bep can i work on this issue ?

@bep bep modified the milestones: v0.115.0, v0.116.0 Jun 30, 2023
@bep bep modified the milestones: v0.116.0, v0.117.0 Aug 1, 2023
@bep bep modified the milestones: v0.117.0, v0.118.0 Aug 30, 2023
@bep bep modified the milestones: v0.118.0, v0.119.0 Sep 15, 2023
@cubxxw
Copy link

cubxxw commented Oct 4, 2023

Is this issue end-of-life?

@bep bep modified the milestones: v0.119.0, v0.120.0 Oct 5, 2023
@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
@bep bep modified the milestones: v0.125.0, Unscheduled Oct 23, 2024
zepyrshut added a commit to zepyrshut/hugo that referenced this issue Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants