FAQ
I'm just learning GO, after decades of using other languages. I like what I
see, but I'm sure I don't understand a lot of stuff.

I'm thinking of writing a simple web application as my first non-trivial go
program. Usual setup, user has browser, makes requests, system spits out
HTML, CSS, JS, etc. and talks to some suitable backend persistent store.

Key questions:

1) in a microservices model, how many "go compilation units" make up the
application? One per command?
2) I assume that the microservices use a templated system to fill in values
for special values in the HTML, so the resulting page can say "Hi Pat"
appropriately. Is there a best-practices templating system?
3) how do you deliver the boring files? CSS, images, Javascript, etc? Does
the main go program deliver them? is there some sort of switch that
dispatches to different processing units depending on the path or some
query parameter?
4) supporting browsers and users who do things like use the Back and
Forward buttons on their browsers is usually done by some MVC framework.
Most (all?) of the frameworks I have used in Java are fat, dumb, ugly, and
verbose. What is the go solution?
5) how do i keep from writing programs that someone would look at and say
"nice professional java code, but not go"?

Thanks
Pat

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Miki Tebeka at Mar 10, 2016 at 4:52 am
    Hi Pat,

    Welcome to Go!

    1) in a microservices model, how many "go compilation units" make up the
    application? One per command?
    There are many ways to do that. A lot of projects go with a "cmd" directory
    which have a subdirectory for each tool. See
    https://talks.golang.org/2014/organizeio.slide#1

    I highly recommend to start Monolith
    <http://martinfowler.com/bliki/MonolithFirst.html> and break it down later.

    2) I assume that the microservices use a templated system to fill in
    values for special values in the HTML, so the resulting page can say "Hi
    Pat" appropriately. Is there a best-practices templating system?
    go has a templating system in https://golang.org/pkg/html/template/.
    There's a nice tutorial at
    https://jannewmarch.gitbooks.io/network-programming-with-go-golang-/content/templates/index.html

    3) how do you deliver the boring files? CSS, images, Javascript, etc? Does
    the main go program deliver them? is there some sort of switch that
    dispatches to different processing units depending on the path or some
    query parameter?
    There is an HTTP file server in the standard library -
    https://golang.org/pkg/net/http/#example_FileServer

    4) supporting browsers and users who do things like use the Back and
    Forward buttons on their browsers is usually done by some MVC framework.
    Most (all?) of the frameworks I have used in Java are fat, dumb, ugly, and
    verbose. What is the go solution?
    Apart from the standard HTTP server which is pretty good. There are several
    other framework out there. I don't have much experience but heard good
    things about https://github.com/gin-gonic/gin.
    Not that today web servers mostly serve initial page and then provide data
    via JSON to a Java script UI framework (such
    as https://facebook.github.io/react/). This makes the web server much
    simpler but the UI more complex. Pick your poison :)

    5) how do i keep from writing programs that someone would look at and say
    "nice professional java code, but not go"?
    You'll probably do at the beginning and then get better - It's OK (I wrote
    Python in Go at the beginning).

    Some resource I think will help are:
    * https://golang.org/doc/effective_go.html
    * https://golang.org/doc/code.html
    * Looking at open source Go code (including the Go standard library)

    HTH,
    --
    Miki


    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Shawn Milochik at Mar 10, 2016 at 4:52 am

    On Wed, Mar 9, 2016 at 11:02 PM, Pat Farrell wrote:

    I'm just learning GO, after decades of using other languages. I like what
    I see, but I'm sure I don't understand a lot of stuff.
    We're all always learning. This is cool. :o)

    I'm thinking of writing a simple web application as my first non-trivial
    go program. Usual setup, user has browser, makes requests, system spits out
    HTML, CSS, JS, etc. and talks to some suitable backend persistent store.

    Key questions:

    1) in a microservices model, how many "go compilation units" make up the
    application? One per command?
    Why do you jump to talking about microservices? How many individual
    projects/repositories/binaries you have is pretty separate from the
    language of choice for each microservice, or whether to even use
    microservices.

    You can use one app with many endpoints, many servers listening on many
    ports, and with millions of concurrent processes (goroutines). Or have many
    individual binaries communicating by whatever means you like. It depends on
    your application.

    2) I assume that the microservices use a templated system to fill in
    values for special values in the HTML, so the resulting page can say "Hi
    Pat" appropriately. Is there a best-practices templating system?
    The standard library includes text/template and html/template. Check those
    out. There's also fmt.Sprintf for simpler things, but if you need to
    sanitize user input look at html/template.

    3) how do you deliver the boring files? CSS, images, Javascript, etc? Does
    the main go program deliver them? is there some sort of switch that
    dispatches to different processing units depending on the path or some
    query parameter?
    Whatever makes sense for you. Use an entirely separate CDN. Serve them with
    nginx. Serve them with your Go application by reading them from disk. Embed
    the bytes of those files directly into your Go binary. Whatever makes sense
    for your needs.

    4) supporting browsers and users who do things like use the Back and
    Forward buttons on their browsers is usually done by some MVC framework.
    Most (all?) of the frameworks I have used in Java are fat, dumb, ugly, and
    verbose. What is the go solution?
    This doesn't seem very Go-specific. If you accept input and process a form,
    you should have your code do a redirect upon success, so that a refresh
    doesn't cause a re-submit or carry any state. But references to browser
    support, MVC frameworks, and Java don't seem to clarify your question.
    Please explain.

    5) how do i keep from writing programs that someone would look at and say
    "nice professional java code, but not go"?
    Every language has its own idioms. If you try to write Java (or Python, or
    any other language) in Go it will not go very well for you. Nothing but
    experience will get you there. The people on this list will help. A lot.
    But don't worry about trying to be perfect, or please everyone, or master
    the language all at once.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Andrew Gerrand at Mar 10, 2016 at 4:59 am
    I wrote some answers to your other questions, but others have since replied
    addressing them, so I will just respond to your last question:
    On 10 March 2016 at 15:02, Pat Farrell wrote:

    5) how do i keep from writing programs that someone would look at and say
    "nice professional java code, but not go"?
    The biggest mistake people make when coming to Go is bringing all their
    habits from other languages.

    My advice is to start simple. At the beginning, try not to think about the
    overall structure. Just start by implementing a web server that says
    "hello". Then serve some static files. Then hook up a database.

    Don't overwhelm yourself with details. At each step, don't try to find a
    pattern or best practice. Instead, do the simplest thing that works.

    As you add more to your program you will see duplicated code. Think about
    how you can abstract that away using functions. Think about how your data
    might be better represented using struct types, and so on.

    If you run into issues, ask focused questions on this mailing list (or
    the gopher
    slack channel <https://blog.gopheracademy.com/gophers-slack-community/>)

    With luck, the complexity of your program should ramp up in correspondence
    with your facility with Go.

    Hope this helps.

    Andrew

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Ranjib Dey at Mar 10, 2016 at 5:56 am
    - 1) in a microservices model, how many "go compilation units" make up the
    application? One per command?
    I'll recommend opposite. Have all code at same place, and define individual
    commands in the same repo that uses same code. Configure make or something
    similar to generate individual binaries. For example influxdb cli client
    and the daemon both are located in same repo.

    - 2) I assume that the microservices use a templated system to fill in
    values for special values in the HTML, so the resulting page can say "Hi
    Pat" appropriately. Is there a best-practices templating system?
    as others mentioned stdlib is pretty solid, but if you are comparing rails
    or django like framework (or even webmachine), I cant think of any. There
    are smaller more versatile frameworks (gorilla, go-kit) which are popular
    to assemble custom solutions.

    3) how do you deliver the boring files? CSS, images, Javascript, etc? Does
    the main go program deliver them? is there some sort of switch that
    dispatches to different processing units depending on the path or some
    query parameter?
    - CDN. If you want to roll your own asset pipeline, combine something like
    aws-sdk with whatever js foo (ember, angular etc ).

    5) how do i keep from writing programs that someone would look at and say
    "nice professional java code, but not go"?
    - Read some of the libraries that you would use/love. I work in operations,
    I have found google's code bases (kubernetes, go-querystring, vitess) ,
    coreos projects (etcd, go-systemd, flannel), hashicorp projects (serf,
    consul, nomad ) to be excellent source of examples. I can compare my own
    works with those, that gives me some idea

    hth
    ranjib
    On Wed, Mar 9, 2016 at 8:58 PM, Andrew Gerrand wrote:

    I wrote some answers to your other questions, but others have since
    replied addressing them, so I will just respond to your last question:
    On 10 March 2016 at 15:02, Pat Farrell wrote:

    5) how do i keep from writing programs that someone would look at and say
    "nice professional java code, but not go"?
    The biggest mistake people make when coming to Go is bringing all their
    habits from other languages.

    My advice is to start simple. At the beginning, try not to think about the
    overall structure. Just start by implementing a web server that says
    "hello". Then serve some static files. Then hook up a database.

    Don't overwhelm yourself with details. At each step, don't try to find a
    pattern or best practice. Instead, do the simplest thing that works.

    As you add more to your program you will see duplicated code. Think about
    how you can abstract that away using functions. Think about how your data
    might be better represented using struct types, and so on.

    If you run into issues, ask focused questions on this mailing list (or the gopher
    slack channel <https://blog.gopheracademy.com/gophers-slack-community/>)

    With luck, the complexity of your program should ramp up in correspondence
    with your facility with Go.

    Hope this helps.

    Andrew

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 10, '16 at 4:32a
activeMar 10, '16 at 5:56a
posts5
users5
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase