Immediate download Software Development with Go Cloud Native Programming using Golang with Linux and Docker 1st Edition Nanik Tolaram ebooks 2024
Immediate download Software Development with Go Cloud Native Programming using Golang with Linux and Docker 1st Edition Nanik Tolaram ebooks 2024
com
https://ebookmeta.com/product/software-development-with-go-
cloud-native-programming-using-golang-with-linux-and-
docker-1st-edition-nanik-tolaram/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/the-comediennes-guide-to-pride-1st-
edition-hayli-thomson-2/
ebookmeta.com
The ConjuPIT Principles The Practical The Tactical The
Intangible For The Thinking Strength Coach Pete Arroyo
https://ebookmeta.com/product/the-conjupit-principles-the-practical-
the-tactical-the-intangible-for-the-thinking-strength-coach-pete-
arroyo/
ebookmeta.com
https://ebookmeta.com/product/business-ethics-a-philosophical-and-
behavioral-approach-2nd-2nd-edition-christian-a-conrad/
ebookmeta.com
Pro Data Mashup for Power BI: Powering up with Power Query
and the M Language to Find, Load, and Transform Data 1st
Edition Adam Aspin
https://ebookmeta.com/product/pro-data-mashup-for-power-bi-powering-
up-with-power-query-and-the-m-language-to-find-load-and-transform-
data-1st-edition-adam-aspin/
ebookmeta.com
https://ebookmeta.com/product/whispering-pines-mysteries-box-set-
books-10-12-shawn-mcguire-et-el/
ebookmeta.com
Lazarus Rising 1st Edition Joseph Caldwell
https://ebookmeta.com/product/lazarus-rising-1st-edition-joseph-
caldwell/
ebookmeta.com
Nanik Tolaram
This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
The publisher, the authors, and the editors are safe to assume that
the advice and information in this book are believed to be true and
accurate at the date of publication. Neither the publisher nor the
authors or the editors give a warranty, expressed or implied, with
respect to the material contained herein or for any errors or
omissions that may have been made. The publisher remains neutral
with regard to jurisdictional claims in published maps and institutional
affiliations.
This Apress imprint is published by the registered company APress
Media, LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
I would like to dedicate this book to my late Dad who stood by me
and encouraged me to write my very first book when I was 17 years
old. To my dearest Mum who always supported me in pursuing my
dreams and encouraged me to keep on going no matter what life
brings. To my beautiful wife and best friend for allowing me the time
to write the book and supporting me in every step of our life. To both
my sons, Rahul and Manav, for allowing me to spend time in front of
the computer on weekends to chase my dream and passion. Last but
not least, to God for giving me this life and opportunity to be where I
am in this world.
Introduction
Go has been out for more than 10 years, and open source projects
were developed using Go. The aim of this book is to show you the
way to use Go to write a variety of applications that are useful in
cloud-based systems.
Deploying applications into the cloud is a normal process that
developers do every day. There are many questions that developers
ask themselves about the cloud, like
1. System Calls
Nanik Tolaram1
(1)
Sydney, NSW, Australia
If you are using Go for the first time, refer to the online
documentation at https://go.dev/doc/install. The online
documentation will walk you through the steps to install Go on your
local computer. Go through the Go tutorial that the Go documentation
provides at https://go.dev/doc/.
Source Code
The source code for this chapter is
available from the
https://github.com/Apress/Software-Development-Go repository.
C System Call
In this section, you will briefly look at how system calls normally work
inside a C program. This will give you an idea of how system calls are
done in C compared to how they are done in Go.
You will see a simple example of using a socket to connect to a
server and read the response. The code can be found inside the
chapter1/c directory. The code creates a socket and uses it to
connect to a public website named httpbin.org and print the
response it receives to the screen. Listing 1-1 shows the sample
code.
#include<stdio.h>
#include<string.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<netdb.h>
if ((server.sin_addr.s_addr = inet_addr(hostname)) ==
0xffffffff) {
if ((host = gethostbyname(hostname)) == NULL) {
return -1;
}
cc sample.c -o sample
Connected
Data Send
Reply received
HTTP/1.1 200 OK
Date: Tue, 01 Mar 2022 10:21:13 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 9593
Connection: close
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
The code sample shows the system call that it uses to resolve
the address of httpbin.org to an IP address by using the
gethostbyname function. It also uses the connect function to use the
newly created socket to connect to the server.
In the next section, you will start exploring Go by using the
standard library to write code using system calls.
sys/unix Package
The sys/unix package is a package provided by the Go language that
provides a system-level interface to interact with the operating
system. Go can run on a variety of operating systems, which means
that it provides different interfaces to applications for different
operating systems. Complete package documentation can be found at
https://pkg.go.dev/golang.org/x/sys/unix. Figure 1-3 shows
different system calls in different operating systems, in this case
between Darwin and Linux.
Figure 1-3 System calls in Linux vs. Darwin
Listing 1-2 shows how to use system calls using the sys/unix
package.
package main
import (
u "golang.org/x/sys/unix"
"log"
)
func main() {
c := make([]byte, 512)
_, err := u.Getcwd(c)
if err != nil {
log.Fatalln(err)
}
log.Println(string(c))
}
The other system call that the application uses is to get the
current working directory using the Getcwd function.
System Call in Go
In the previous section, you looked at a simple example of using the
sys/unix package. In this section, you will explore more on system
calls by looking at an open source project. The project can be found
at https://github.com/tklauser/statx. This project works similarly to
the stat command in Linux for printing out statistical information
about a particular file.
Change your directory to the statx project and compile and run
the app as follows:
File: ./README.md
Size: 476 Blocks: 8 IO Block:
4096 regular file
Device: fd01h/64769d Inode: 2637168 Links: 1
Access: (0644/-rw-r--r--) Uid: (1000/ nanik) Gid:
(1000/ nanik)
Access: 2022-02-19 18:10:29.919351223 +1100 AEDT
Modify: 2022-02-19 18:10:29.919351223 +1100 AEDT
Change: 2022-02-19 18:10:29.919351223 +1100 AEDT
Birth: 2022-02-19 18:10:29.919351223 +1100 AEDT
Attrs: 0000000000000000 (-----....)
How does the application get all this information about the file?
It obtains the information from the operating system by making a
system call. Let's take a look at the code in Listing 1-3.
import (
....
"golang.org/x/sys/unix"
)
....
func main() {
log.SetFlags(0)
flag.Parse()
if len(flag.Args()) < 1 {
flag.Usage()
os.Exit(1)
}
....
for _, arg := range flag.Args() {
var statx unix.Statx_t
if err := unix.Statx(unix.AT_FDCWD, arg, flags, mask,
&statx); err != nil {
....
dev := unix.Mkdev(statx.Dev_major, statx.Dev_minor)
....
}
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.