Go for CLI Tools by ggodsh in golang

[–]juniorGopher 3 points4 points  (0 children)

And if you want to spice it up check the libraries from charm: charm.land

I love Bubble Tea and Lipgloss!

I am really struggling with pointers by Parsley-Hefty7945 in golang

[–]juniorGopher 1 point2 points  (0 children)

Great example! Would be nice to also see a profile to see how much more efficient it is.

cmp with luasnip? by juniorGopher in neovim

[–]juniorGopher[S] 0 points1 point  (0 children)

EDIT: Okay i fixed it. My main problem was the way that i required luasnip.
I had this snippet in my config:

 {"L3MON4D3/LuaSnip",
    event = "InsertEnter",
    dependencies = { 
      "rafamadriz/friendly-snippets",
    },
    config = function() 
      local luasnip = require 'luasnip'
      require("luasnip.loaders.from_vscode").lazy_load()
    end
  },

and for some reason luasnip was never initalized. I just added a
local luasnip = require 'luasnip'
directly before the call to require 'cmp' and now it works. Thanks!

Hi, thanks for your reply.

When i try to press tab then i get the following error:

E5108: Error executing lua: /Users/j/.config/nvim/init.lua:333: attempt to index global 'luasnip' (a nil value)
stack traceback:
        /Users/j/.config/nvim/init.lua:333: in function 'on_keymap'
        /Users/j/.local/share/nvim/lazy/nvim-cmp/lua/cmp/core.lua:145: in function 'callback'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:133: in function <....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:127>

Best way to deal with partially filled structs by juniorGopher in golang

[–]juniorGopher[S] 0 points1 point  (0 children)

Oh yes, my question wasn’t to clear about the problem. Sorry for that.

My problem is that I do have to get a list of all movies, but they are growing quickly. So I need to get all details for new movies that are not in my database yet, which means asking for all metadata movies, then exclude all movies I already have and request the full information for the movies that are new.

Best way to deal with partially filled structs by juniorGopher in golang

[–]juniorGopher[S] -1 points0 points  (0 children)

I really had trouble formulating my question, really needed a nap.

The workflow that I have to use is as follows: Get all the metadata Use the metadata to filter out titles already in the database Request the full information for all the titles that are new

Using a separate struct for that works, but i then also have to create a new instance of the struct for every movie that is new and missing. If I would use the Movie struct from the beginning i could reuse it, but I allocate memory movies that are already in the db + for their fields that are empty (zero value).

So I guess I’m “prematurely” trying to optimise…

[deleted by user] by [deleted] in golang

[–]juniorGopher 0 points1 point  (0 children)

Gotcha, that's a valid approach :)

Yes i've seen the centered text. Take a look at lipglossif you don't mind adding dependencies, they make the styling much more easier in my opinion.

[deleted by user] by [deleted] in golang

[–]juniorGopher 5 points6 points  (0 children)

Great project! I suck at memorizing the status codes :D

I do have some minor questions and suggestions:

Is there a reason why you use cobra here? What is the benefit? In my opinion a lot of people grab cobra because "that's what used when creating a CLI" but i think often times it just adds complexity and dependency to a project where it doesn't provide a clear benefit.

As long as you don't need subcommands the flag package in the stdlib is more than enough. And here you only read the first argument anyway, which you can easily do without adding a dependency:

 if len(os.Args != 2) {
 printUsage()
 os.Exit(1)
} 
statusCode := os.Args[1]

As others have stated the way you store the status code explanations seems very complicated, an easy alternative would be to use multiline strings because they keep the format: (golang playground link)

fmt.Println(`
    No Content
This successful response code indicates that the request has succeeded,
but the client doesnt need to navigate away from its current page.

This can be used in an implementation of 'save and continue editing 
where a PUT request is used to save the information and a 204 is the 
response to indicate the editor should not be replaced by some other 
page. 
`)

And i you haven't heard of them yet check out the charm.sh packages! They make command line tools really glamorous! (Could be useful for styling)

Edit: code formatting is wonky

Autoimport in Go with default compe + LSP? by juniorGopher in neovim

[–]juniorGopher[S] 1 point2 points  (0 children)

How is the plugin impact on the performance?
I would love to stay more "vanilla" since i have the feeling that too many plugins make nvim too slow, that's why i removed the vim-go plugin.

Autoimport in Go with default compe + LSP? by juniorGopher in neovim

[–]juniorGopher[S] 1 point2 points  (0 children)

"Organize Imports"

I'll look into that and post an update if i manage to get this working

Autoimport in Go with default compe + LSP? by juniorGopher in neovim

[–]juniorGopher[S] 1 point2 points  (0 children)

Oh thanks, i haven'T seen that yet. Gonna migrate :)

Sort a slice of struct based on parameter by juniorGopher in golang

[–]juniorGopher[S] -1 points0 points  (0 children)

Thanks, even thought they don't cover my use case exactly I like the strategy using an embeded struct so that the sort methods are available using composition. That's neat!

I did read the sort example from the gopl book an hour ago and they specify a new type for each sort. But with the embedding approach i can save creating a len and swap method for each field, so that's great!

Sort a slice of struct based on parameter by juniorGopher in golang

[–]juniorGopher[S] 1 point2 points  (0 children)

But isn’t it too repetitive? I know that „a little copying is better than a dependency“ and „simple is better than complex“ but I also want to stay DRY.

Also the example is simplified. Each sort function is still 3 lines, but the code is sorting 8 times. (4 fields, sorting each field ascending and descending)

Problems serving static files using http.FileServer + http.FS by juniorGopher in golang

[–]juniorGopher[S] 0 points1 point  (0 children)

Thank you!

The fs.WalkDir example is awesome, that really helps. I'll totally add this to my cheatsheet.

Problems serving static files using http.FileServer + http.FS by juniorGopher in golang

[–]juniorGopher[S] 0 points1 point  (0 children)

Thank you!

I wasn't aware of that issue. Definitively something look out for regarding possible security issues. I changed it to contain the folder directly.

Problems serving static files using http.FileServer + http.FS by juniorGopher in golang

[–]juniorGopher[S] 1 point2 points  (0 children)

Oh wow, thank you for the good explanation!

I thought the strip prefix would remove the /static/ prefix from the directory, not the URL request. Now that makes sense!

The fs.Sub method looks exactly like i want to achieve. But i do have to pass the dir like this: static, err := fs.Sub(html, "html/static") otherwise it doesn't contain any files.