blog

mihalis's picture

Mastering Go FAQ

1. Does the book have a web page?
Yes: Mastering Go web page and Mastering Go TOC.

2. Is Mastering Go good for amateur programmers?
Although anyone can read Mastering Go, if you have never programmed before, Mastering Go might not be the best choice.

3. Who is this book for?
Mastering Go is for people who are already familiar with Go or any other programming language and want to take their Go knowledge to the next level!

4. Is Mastering Go different from Go Systems Programming?
Go Systems Programming is about learning to develop system tools in Go. Mastering Go is about learning the characteristics and the inner workings of the Go Programming Language in order to write better Go code.

5. Why buy Mastering Go?
Because Mastering Go will make you a better Go developer. The book contains many autonomous examples in order to illustrate the Go topics that it covers.

6. Have more questions?
Contact me using http://www.mtsoukalos.eu/contact.

You can get Mastering Go from Packt, Amazon.com, Amazon.co.uk, or any other Amazon store.

Tags: 
mihalis's picture

Mastering Go TOC

Mastering Go Table Of Contents:

Chapter 1: Go and the Operating System
Chapter 2: Understanding Go Internals
Chapter 3: Working with Basic Go Data Types
Chapter 4: The Uses of Composite Types
Chapter 5: Enhancing Go code with Data Structures
Chapter 6: What you might not know about Go Packages
Chapter 7: Reflection and Interfaces for all seasons
Chapter 8: Telling a UNIX system what to do
Chapter 9: Go Concurrency – Goroutines, Channels and Pipelines
Chapter 10: Go Concurrency – Advanced Topics
Chapter 11: Code Testing, Optimization and Profiling
Chapter 12: The Foundations of Network Programming in Go
Chapter 13: Network Programming – Building Servers and Clients

mihalis's picture

What is Systems Programming?

Systems programming is a special area of programming on UNIX machines. Most commands that have to do with System Administration tasks such as disk formatting, network interface configuration, module loading, kernel performance tracking, etc. are implemented using the techniques of Systems Programming. Additionally, the /etc directory, which can be found on all UNIX systems, contains plain text files that deal with the configuration of a UNIX machine and its services and are also manipulated using systems software.

You can group the various areas of systems software and related system calls in the following sets:

  • File I/O: this area deals with file reading and writing operations, which is the most important task of an operating system. File input and output must be fast and efficient but, above all, it must be reliable.
  • Advanced File I/O: apart from the basic input and output system calls, there are also more advanced ways to read or write to a file including asynchronous I/O and non-blocking I/O.
  • System Files and Configuration: this group of systems software includes functions that allow you to handle system files such as /etc/passwd and get system specific information such as system time and DNS configuration.
  • Files and Directories: this cluster includes functions and system calls that allow the programmer to create and delete directories and get information such as the owner and the permissions of a file or a directory.
  • Process Control: this group of software allows you to create and interact with UNIX processes.
  • Threads: when a process has multiple threads, it can perform multiple tasks. However, threads must be created, terminated and synchronized, which is the purpose of this collection of functions and system calls.
  • Server Processes: this set includes techniques that allow you to develop server processes, which are processes that get executed in the background without the need for an active terminal.
  • Interprocess Communication: this set of functions allows processes that run on the same UNIX machine to communicate with each other using features such as pipes, FIFOs, message queues, semaphores and shared memory.
  • Signal Processing: signals offer processes a way of handling asynchronous events, which can be very handy. Almost all server processes have extra code that allows them to handle UNIX signals using the system calls of this group.
  • Network Programming: this is the art of developing applications that work over computer networks with the help of TCP/IP and is not Systems programming per se. However, most TCP/IP servers and clients are dealing with system resources, users, files and directories so most of the times you cannot create network applications without doing some kind of Systems programming.

    The challenging thing with Systems Programming is that you cannot afford to have an incomplete program; you can either have a fully working, secure program that can be used on a production system or nothing at all. This mainly happens because you cannot trust end users and hackers!

    Want to learn about Systems Programming using Go?
    Get my book Go Systems Programming from Packt or from Amazon.com.

  • mihalis's picture

    Concurrency and Parallelism

    It is a very common misconception that Concurrency and Parallelism is the same thing, which is far from true! Parallelism is the simultaneous execution of multiple things whereas Concurrency is a way of structuring your components so that they can be independently executed when possible.
    It is only when you build things concurrently that you can safely execute them in parallel, when and if your operating system and your hardware permits it. The Erlang programming language did this a long time ago, long before CPUs had multiple cores and computers had lots of RAM.
    In a valid concurrent design, adding concurrent entities makes the whole system run faster because more things can run in parallel. So, the desired parallelism comes from a better concurrent expression and implementation of the problem. The developer is responsible for taking concurrency into account during the design phase of a system and benefit from a potential parallel execution of the components of the system. So, the developer should not think about parallelism but about breaking things into independent components that solve the initial problem when combined.
    Even if you cannot run your functions in parallel on a UNIX machine, a valid concurrent design will still improve the design and the maintainability of your programs. In other words, Concurrency is better than Parallelism!

    Want to learn more about the Go Concurrency model?
    Get my book Go Systems Programming from Packt or from Amazon.com.
    Or get my other book Mastering Go from Packt or from Amazon.com.

    Tags: 
    mihalis's picture

    Copying a file in Go

    This blog post will show some of the ways that you can copy a file in Go.

    Using io.Copy()
    The simplest way to copy a file is by using the io.Copy() function. You can find the entire Go code at https://github.com/mactsouk/fileCopyGo/blob/master/ioCopy.go.
    The most important part of the utility is the next Go code:

    nBytes, err := io.Copy(destination, source)

    So, with just a single call, you can copy a file. Although this is fast, it does not give you any flexibility or any control over the whole process.

    Using ioutil.WriteFile() and ioutil.ReadFile()
    You can copy a file in Go by using ioutil.WriteFile() and ioutil.ReadFile(). You can find the entire source file at https://github.com/mactsouk/fileCopyGo/blob/master/readWriteAll.go.
    The most important part of readWriteAll.go is the next two Go statements:

    input, err := ioutil.ReadFile(sourceFile)
    err = ioutil.WriteFile(destinationFile, input, 0644)

    The first statement reads the entire source file whereas the second statement writes the contents of the input variable to a new file.
    Notice that reading the entire file and storing its contents to a single variable might not be very efficient when you want to copy huge files. Nevertheless, it works!

    Using os.Read() and os.Write()
    The last technique uses os.Read() for reading small portions of the input file into a buffer and os.Write() for writing the contents of that buffer to the new file. Notice that the size of the buffer is given as a command line argument, which makes the process very flexible.
    You can find the entire code at https://github.com/mactsouk/fileCopyGo/blob/master/cpBuffer.go.
    The most important statements of the implementation of the Copy() function are the next:

    buf := make([]byte, BUFFERSIZE)
    n, err := source.Read(buf)
    _, err := destination.Write(buf[:n])

    The first statement creates a byte slice with the desired size. The second statement reads from the input file whereas the third statement writes the contents of the buf buffer to the destination file.

    Want to learn more about File I/O in Go?
    Get my book Go Systems Programming from Packt or from Amazon.com.

    Want to be able to benchmark File I/O operations?
    Get my book Mastering Go from Packt or from Amazon.com.

    Tags: 

    Pages

    Subscribe to RSS - blogs