Website in golang

https://github.com/keygenqt/golang-ligh

Hello, today promptly inserted at first, the structure of the future site. You can see if you like it. If any serious mistakes, if the paths can better implementation?

1 Like

i have two observations:

  • a little complicated as code structure. using gorilla mux you can write much clean code.

  • a good practice is to not use relative paths when you write web servers or applications, especially when you use templates because if you run it on a server from other location than current directory loading this files will not work. instead, use something like this:

    pwd, err := filepath.Abs(filepath.Dir(os.Args[0]))
    if err != nil {
    os.Exit(1)
    }

    SetLayoutsPath(pwd+"/views/frontend/layouts")

1 Like

Thank you! I used a relative path, and will make the code more clear, it is a draft :). But the structure is acceptable in golang?

hard to say. basically, any functional program is acceptable. i guess it’s a matter of style how each program is structured.

Ok, thanks. My first application on c ++ has caused a storm of emotions in people. If it is not then the code is acceptable)

about code structure must be mentioned that golang is a little different than other languages (C for example where you include files). at some point you will need to structure the code in subfolders. but the code from an subfolder in go is a package and you need to know how to work with. so, you must take care about this when you write more complex programs.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.