How to write a web app in GO?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
32 views
Hey, GO teach, simultaneously trying to write an application to GO is easy to work with twitch API, but I can't figure out how to organize the project structure(due to the lack of experience in development) already 3 day I sit I twist-I twirl, and I do not know how to do this, now do this:
goTwitch the root directory of the project
- model - working with databases and Consul
- controller - and-down stick handling configs(parsers) has not yet come up what else will
- route is ranting and applications
- templates - this template application

It seems to me this structure some crap
the main file looks like so

package main import ( "goTwitch/controller" "fmt" "net/http" "time" "log" "goTwitch/route" ) func main() { Serverconfig := controller.ConfigPars() //config parsim handler := http.NewServeMux() handler.HandleFunc("/hello/" , route.Handlers(w http.Request, r *http.Request {})) Is a function handler from file route s := http.Server{ //server Settings Addr: Serverconfig.Port Handler: handler, ReadTimeout: time.Duration(Serverconfig.ReadTimeout) * time.Second, WriteTimeout: time.Duration(Serverconfig.WriteTimeout) * time.Second, } log.Fatal(s.ListenAndServe()) -//start the server }


File route

package route import "net/http" Handlers func(r *http.Request) { Cahokia-code processing }


config.go - parsim yaml with the configuration of the web server
package controller import ( "io/ioutil" "path/filepath" "gopkg.in/yaml.v2" "log" ) type Serverconfig struct { Port string `yaml:"Port"` ReadTimeout int `yaml:"ReadTimeout"` WriteTimeout int `yaml:"WriteTimeout"` } ConfigPars func() *Serverconfig { filename, _ := filepath.Abs("./config.yml") yamlFile, err := ioutil.ReadFile(filename) if err != nil { panic(err) } Serverconfig := &Serverconfig{} //err = yaml.Decoder{ &Serverconfig} err = yaml.Unmarshal(yamlFile, &Serverconfig) if err != nil { log.Fatal(err) } return Serverconfig }


While all this looks like this has already been tried many variants don't think I dwell on this, but I feel this is also not the right approach.

There is still a question tangential parser a yaml file, if from yaml file to remove the Port: :9090 config is parsed and does not swear on something that does not coincide with the structure to go, what am I doing wrong? like if the structure in the go file is not the same Unmarshal same sort of mistake have to give?
by | 32 views

3 Answers

0 like 0 dislike
For a start, take to work. The structure and everything else is formed over time based on the real requirements, facts so to speak, and not on guesses and predictions. Upon receipt of the new features and requirements of the code will continue to evolve and change, and in the process, the right decisions to come.
by
0 like 0 dislike
revel take, for example, as the basis.
or beego.me
by
0 like 0 dislike
but I can't figure out how to organize the project structure(due to the lack of experience in development)

Take a ready-made framework, which implies opredelennuyu organization.

So complete frameworks for web applications does not need to Go.
But in your case, it should take them that they sent.
Full, not abbreviated. That is the type of Revel.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 20, 2019 by oolooq
0 like 0 dislike
1 answer
asked Apr 9, 2019 by alina-maslo
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,251 users