Categories: DatabasesNews

go from Blog Posts – SQLServerCentral

1 min read

Starter Template

I saved this as a snippet for vscode to get up and running quickly with something better than the defaults for handling func main isolation.

I’ve been working on modifying this a bit as I don’t really like using args, but am trying not to overcomplicate things as a new gopher.

I tend to like better flag parsing than using args, but it’s still a better pattern to get functions isolated from main to easily test.

The gist that I’ve taken from this and discussions in the community is ensure that main is where program termination is dedicated instead of handling this in your functions.

This isolation of logic from main ensures you can more easily setup your tests as well, since func main() isn’t testable.

package main
// package template from:
import (
"errors"
"fmt"
"io"
"os"
)
const (
// exitFail is the exit code if the program
 // fails.
 exitFail = 1
)
func main() {
if err := run(os.Args, os.Stdout); err != nil {
fmt.Fprintf(os.Stderr, "%sn", err)
os.Exit(exitFail)
}
}
func run(args []string, stdout io.Writer) error {
if len(args) == 0 {
return errors.New("no arguments")
}
for _, value := range args[1:] {
fmt.Fprintf(stdout, "Running %s", value)
}
return nil
}

Puzzles – FizzBuzz

I honestly had never done any algorithm or interview puzzles beyond sql-server, so I was really happy to knock this out relatively easily.

At least I pass the basic Joel test ??

#development #golang

The post go appeared first on SQLServerCentral.

Share
Published by

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago