Learn how to use the elastic search Go client to retrieve data from elastic search| golangbot
Admission Controllers Admission controllers provide a mechanism to validate or modify Kubernetes object creation requests before the object is actually created. This definition might not make complete sense right now but we will be able to understand what this means as the tutorial progresses, so don’t worry about it :). There are two kinds of admission controllers in Kubernetes. Validating admission controller Mutating admission controller Let’s try to understand each of them by means of...| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
What are WebSockets and what are their advantages over traditional HTTP? HTTP is simply a request response protocol. This means a client such as a web browser sends a request and the server works on this request and sends a response. This request and response uses a TCP connection underneath. Once the response is received, the TCP connection is closed and can’t be reused. The client has to initiate a new TCP connection if it wants to make a new request.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Why migrate to Hugo? Why migrate golangbot.com from Ghost to Hugo is the first question that will pop in your mind when you read this post. golangbot.com is 6 years old and it has been powered by Ghost since its inception. Ghost has stood the test of time and it has served me well. Why migrate to Hugo then? Well I have my own reasons. Ghost doesn’t support SQLite anymore Ghost has been supporting SQLite and MySQL as the backend store.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
What is a context? Context is a package in the standard library which is mainly used to propagate cancellation signals from one function to another or even from micro service to another. Let’s consider the example of a user sending a get request to a web server to download 50 images, zip it and send the zipped response back. The request has been triggered from the browser and let’s say it takes 70 seconds to complete.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 32 in our Golang tutorial series. In this tutorial we will learn about error wrapping in Go and why do we even need error wrapping. Let’s get started. What is error wrapping? Error wrapping is the process of encapsulating one error into another. Let’s say we have a web server which accesses a database and tries to fetch a record from the DB. If the database call returns an error, we can decide whether to wrap this error or send our own custom error from the webserv...| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 3 in our MySQL tutorial series. In the previous tutorial, we discussed creating a table and inserting rows into the table. In this tutorial, we will learn how to select a single row as well as multiple rows from a table. MySQL Series Index Connecting to MySQL and creating a Database Creating a Table and Inserting Rows Selecting Single Row and Multiple rows Prepared statements - WIP| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 2 in our MySQL tutorial series. In the first tutorial, we discussed how to connect to MySQL and create a database. In this tutorial, we will learn how to create a table and insert records into that table. MySQL Series Index Connecting to MySQL and creating a Database Creating a Table and Inserting Rows Selecting single and multiple rows Prepared statements - WIP Updating rows - WIP| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 1 in our MySQL tutorial series. In this tutorial, we will connect to MySQL and create a database. We will also ping the DB to ensure that the connection is established properly. MySQL Series Index Connecting to MySQL and creating a Database Creating a Table and Inserting Rows Selecting single and multiple rows Prepared statements - WIP Updating rows - WIP Deleting rows - WIP Importing the MySQL driver The first step in creating the MySQL database is to download the MyS...| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 2 of our WebAssembly tutorial series. Series Index Introduction to WebAssembly Using Go Accessing DOM from Go using Javascript In the first tutorial of this tutorial series, we created and exposed a function from Go and called it using JavaScript. I highly recommend reading the first part first part if you have not read it yet. In this tutorial, we will develop a UI for our application, handle errors and also manipulate the DOM of the browser from Go.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Need for a debugger The simplest form of debugging in any programming language is by using print statements/logs and writing to standard out. This definitely works but becomes extremely difficult when the size of our application grows and the logic becomes more complex. Adding print statements to every code path of the application is not easy. This is where debuggers come in handy. Debuggers help us to trace the execution path of the program using breakpoints and a host of other features.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial number 7 in Golang tutorial series. What are packages and why are they used? So far we have seen Go programs that have only one file with a main function and a couple of other functions. In real-world scenarios, this approach of writing all source code in a single file is not scalable. It becomes impossible to reuse and maintain code written this way. This is where packages are helpful.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
I am working on a DIY Pick and Place Robot course with my friend Balaji. I am taking care of the software side of things while the hardware is taken care by Balaji. Description A pick and place robotic system automates the process of picking up parts and placing them in a desired location. These robots plays a major role in industrial automation. The system consists of links, joints & gripper equivalent to a human hand.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
This is the second tutorial in our Golang tutorial series. Please read our previous tutorial Golang Introduction and Installation to know about what is Golang and how to install Golang. There is no better way to learn a programming language than getting our hands dirty with code. Let’s go ahead and write our first Go program. Setting up the development environment Let’s create a directory where we want to write our hello world program.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Here are all the quizzes posted on Twitter and Facebook in June 2019 and their explanation. Quiz 1 1package main 2 3import ( 4 "fmt" 5) 6 7func hello() []string { 8 return nil 9} 10 11func main() { 12 h := hello 13 if h == nil { 14 fmt.Println("nil") 15 } else { 16 fmt.Println("not nil") 17 } 18} Run in playground Options nil not nil compilation error Answer not nil We assign the function hello to the variable h and not the return value of hello() in line no.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 4 in our Resumable file uploader series. In the previous tutorials, we coded our resumable tus server using Go. In this tutorial we will use curl and dd commands to test the tus server. Testing We have the resumable file upload tus server ready but we have not tested it yet. We need a tus client to test the tus server. We will create the Go client in the upcoming tutorials.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 3 in our Resumable file uploader series. The previous tutorials provided an introduction about the tus protocol and we also created the DB CRUD methods. In this tutorial, we will create the http handlers to support the POST, PATCH and HEAD http methods. This tutorial has the following sections POST http handler HEAD http handler PATCH http handler File validation Upload complete validation Upload offset validation Content length validation File patch POST http handler ...| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 2 in our Resumable file uploader series. The last tutorial explained how tus protocol works. I strongly recommend reading the previous tutorial if you are new to tus. In this tutorial, we will create the data model and the database CRUD methods. This tutorial has the following sections Data model Table creation Tus Recollection Creating file Updating file Get file Data model Let’s first discuss the data model for our tus server.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 1 in our Resumable file uploader series. How many times have you tried to upload a large file only to know that it failed because of a network issue! When you re-upload the file again, the upload starts from the beginning :(. Not cool at all. This is where resumable file uploaders come in handy. Resumable file uploaders allow the file upload to start right from the point where it stopped instead of uploading the whole file again.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 37 in Golang tutorial series. In this tutorial, we will learn how to write data to files using Go. We will also learn how to write to a file concurrently. This tutorial has the following sections Writing string to a file Writing bytes to a file Writing data to a file line by line Appending to a file Writing to a file concurrently Please run all the programs of this tutorial in your local system as playground doesn’t support file operations.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 36 in Golang tutorial series. File reading is one of the most common operations performed in any programming language. In this tutorial, we will learn about how files can be read using Go. This tutorial has the following sections. Reading an entire file into memory Using an absolute file path Passing the file path as a command line flag Bundling the file inside the binary Reading a file in small chunks Reading a file line by line Reading an entire file into memory One ...| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 35 in Golang tutorial series. Reflection is one of the advanced topics in Go. I will try to make it as simple as possible. This tutorial has the following sections. What is reflection? What is the need to inspect a variable and find its type? reflect package reflect.Type and reflect.Value reflect.Kind NumField() and Field() methods Int() and String() methods Complete program Should reflection be used? Let’s discuss these sections one by one now.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 34 in Golang tutorial series. What are first class functions? A language that supports first class functions allows functions to be assigned to variables, passed as arguments to other functions and returned from other functions. Go has support for first class functions. In this tutorial, we will discuss the syntax and various use cases of first class functions. Anonymous functions Let’s start with a simple example which assigns a function to a variable.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 33 in Golang tutorial series. What is Panic? The idiomatic way of handling abnormal conditions in a Go program is using errors. Errors are sufficient for most of the abnormal conditions arising in the program. But there are some situations where the program cannot continue execution after an abnormal condition. In this case, we use panic to prematurely terminate the program. When a function encounters a panic, its execution is stopped, any deferred functions are execut...| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 31 in our Golang tutorial series. In the last tutorial we learnt about error representation in Go and how to handle errors from the standard library. We also learnt how to extract more information from the errors. This tutorial deals with how to create our own custom errors which we can use in our functions and packages. We will also use the same techniques employed by the standard library to provide more details about our custom errors.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 30 in Golang tutorial series. What are errors? Errors indicate any abnormal condition occurring in the program. Let’s say we are trying to open a file and the file does not exist in the file system. This is an abnormal condition and it’s represented as an error. Errors in Go are plain old values. Just like any other built-in type such as int, float64, … error values can be stored in variables, passed as parameters to functions, returned from functions, and so on.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 29 in Golang tutorial series. What is Defer? Defer statement is used to execute a function call just before the surrounding function where the defer statement is present returns. The definition might seem complex but it’s pretty simple to understand by means of an example. Example 1package main 2 3import ( 4 "fmt" 5 "time" 6) 7 8func totalTime(start time.Time) { 9 fmt.Printf("Total time taken %f seconds", time.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 28 in Golang tutorial series. Polymorphism in Go is achieved with the help of interfaces. As we have already discussed, interfaces are implicitly implemented in Go. A type implements an interface if it provides definitions for all the methods declared in the interface. Let’s see how polymorphism is achieved in Go with the help of interfaces. Polymorphism using an interface Any type which provides definition for all the methods of an interface is said to implicitly im...| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 27 in Golang tutorial series. Go does not support inheritance, however, it does support composition. The generic definition of composition is “put together”. One example of composition is a car. A car is composed of wheels, an engine and various other parts. Composition by embedding structs Composition can be achieved in Go is by embedding one struct type into another. A blog post is a perfect example of composition.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 26 in Golang tutorial series. Is Go Object Oriented? Go is not a pure object oriented programming language. This excerpt taken from Go’s FAQs answers the question of whether Go is Object Oriented. Yes and no. Although Go has types and methods and allows an object-oriented style of programming, there is no type hierarchy. The concept of “interface” in Go provides a different approach that we believe is easy to use and in some ways more general.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 25 in Golang tutorial series. In this tutorial, we will learn about mutexes. We will also learn how to solve race conditions using mutexes and channels. Critical section Before jumping to mutex, it is important to understand the concept of critical section in concurrent programming. When a program runs concurrently, the parts of code which modify shared resources should not be accessed by multiple Goroutines at the same time.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 24 in Golang tutorial series. What is select? The select statement is used to choose from multiple send/receive channel operations. The select statement blocks until one of the send/receive operations is ready. If multiple operations are ready, one of them is chosen at random. The syntax is similar to switch except that each of the case statements will be a channel operation. Let’s dive right into some code for better understanding.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 23 in Golang tutorial series. What are buffered channels? All the channels we discussed in the previous tutorial were basically unbuffered. As we discussed in the channels tutorial in detail, sends and receives to an unbuffered channel are blocking. It is possible to create a channel with a buffer. Sends to a buffered channel are blocked only when the buffer is full. Similarly receives from a buffered channel are blocked only when the buffer is empty.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 22 in Golang tutorial series. In the previous tutorial, we discussed about how concurrency is achieved in Go using Goroutines. In this tutorial we will discuss about channels and how Goroutines communicate using channels. What are channels Channels can be thought of as pipes using which Goroutines communicate. Similar to how water flows from one end to another in a pipe, data can be sent from one end and received from the other end using channels.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 21 in Golang tutorial series. In the previous tutorial, we discussed concurrency and how it is different from parallelism. In this tutorial, we will discuss how concurrency is achieved in Go using Goroutines. What are Goroutines? Goroutines are functions or methods that run concurrently with other functions or methods. Goroutines can be thought of as lightweight threads. The cost of creating a Goroutine is tiny when compared to a thread.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 20 in Golang tutorial series. Go is a concurrent language and not a parallel one. Before discussing how concurrency is taken care in Go, we must first understand what is concurrency and how it is different from parallelism. What is concurrency? Concurrency is the capability to deal with lots of things at once. It’s best explained with an example. Let’s consider a person jogging. During his morning jog, let’s say his shoelaces become untied.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 19 in Golang tutorial series. This is the second part in our 2 part interface tutorial. In case you missed the first part, you can read it here interfaces-part-1. Implementing interfaces using pointer receivers vs value receivers All the interfaces we discussed in part 1 were implemented using value receivers. It is also possible to implement interfaces using pointer receivers. There is a subtlety to be noted while implementing interfaces using pointer receivers.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 18 in Golang tutorial series. This is the first part in our 2 part interface tutorial. What is an interface? In Go, an interface is a set of method signatures. When a type provides definition for all the methods in the interface, it is said to implement the interface. Interface specifies what methods a type should have and the type decides how to implement these methods.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 17 in Golang tutorial series. Introduction A method is just a function with a special receiver type between the func keyword and the method name. The receiver can either be a struct type or non-struct type. The syntax of a method declaration is provided below. func (t Type) methodName(parameter list) { } The above snippet creates a method named methodName with receiver type Type. t is called as the receiver and it can be accessed within the method.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 16 in our Golang tutorial series. What is a struct? A struct is a user-defined type that represents a collection of fields. It can be used in places where it makes sense to group the data into a single unit rather than having each of them as separate values. For instance, an employee has a firstName, lastName and age. It makes sense to group these three properties into a single struct named Employee.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 15 in Golang tutorial series. In this tutorial, we will learn how pointers work in Go and we will also understand how Go pointers differ from pointers in other languages such as C and C++. This tutorial has the following sections. What is a pointer? Declaring pointers Zero value of a pointer Creating pointers using the new function Dereferencing a pointer Passing pointer to a function Returning pointer from a function Do not pass a pointer to an array as an argument to...| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 14 in Golang tutorial series. Strings deserve a special mention in Go as they are different in implementation when compared to other languages. What is a String? A string is a slice of bytes in Go. Strings can be created by enclosing a set of characters inside double quotes " ". Let’s look at a simple example that creates a string and prints it. 1package main 2 3import ( 4 "fmt" 5) 6 7func main() { 8 name := "Hello World" 9 fmt.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 13 in Golang tutorial series. What is a map? A map is a inbuilt data type in Go which is used to store key-value pairs. A practical use case for a map is for storing the currency codes and the corresponding currency names. USD - United States Dollar EUR - Euro INR - India Rupee A map will be a perfect fit for the above use case use case.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to part 12 of our Golang tutorial series. What is a variadic function? Functions in general accept only a fixed number of arguments. A variadic function is a function that accepts a variable number of arguments. If the last parameter of a function definition is prefixed by ellipsis …, then the function can accept any number of arguments for that parameter. Only the last parameter of a function can be variadic.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to the part 11 of Golang tutorial series. In this tutorial, we will learn about Arrays and Slices in Go. Arrays An array is a collection of elements that belong to the same type. For example, the collection of integers 5, 8, 9, 79, 76 forms an array. Mixing values of different types, for example, an array that contains both strings and integers is not allowed in Go. Declaration An array belongs to type [n]T.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
This is tutorial number 10 in Golang tutorial series. What is a switch statement? A switch is a conditional statement that evaluates an expression and compares it against a list of possible matches and executes the corresponding block of code. It can be considered as an idiomatic way of replacing complex if else clauses. Example An example program is worth a hundred words. Let’s start with a simple example which will take a finger number as input and outputs the name of that finger :) .| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial number 9 in Golang tutorial series. A loop is used to execute a block of code repeatedly until a condition is satisfied. for is the only loop available in Go. Go doesn’t have while or do while loops which are present in other languages like C. for loop syntax for initialisation; condition; post { } The initialisation statement will be executed only once. After the loop is initialised, the condition is checked.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial number 8 of our Golang tutorial series. if statement has a condition and it executes a block of code if that condition evaluates to true. It executes an alternate else block if the condition evaluates to false. In this tutorial we will look at the various syntaxes for using a if statement. If statement syntax The syntax of the if statement is provided below if condition { } If the condition evaluates to true, the block of code between the braces { and } is executed.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
This tutorial is now deprecated. Please click here for the updated version. Welcome to tutorial number 7 in Golang tutorial series. What are packages and why are they used? So far we have seen go programs which have only one file which has a main function with a couple of other functions. In real world scenarios this approach to writing all source code in a single file will not work. It becomes impossible to reuse and maintain code written this way.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 6 in our Golang tutorial series. What is a function? A function is a block of code that performs a specific task. A function takes an input, performs some operations on the input and generates outputs. For example, a function can take the radius as input and calculate the area and circumference as output. Function declaration The following is the syntax for declaring a function in Go| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial no. 5 in our Golang tutorial series. What is a constant? Constants in Go is used to denote fixed static values such as 95 "I love Go" 67.89 and so on. Constants are generally used to represent values that do not change throughout the life time of an application. Declaring a constant The keyword const is used to declare a constant in Go. Let’s see how to declare a constant by means an example.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Welcome to tutorial number 4 in our Golang tutorial series. Please read Golang tutorial part 3: Variables of this series to learn about variables. The following are the basic data types available in Go bool Numeric Types int8, int16, int32, int64, int uint8, uint16, uint32, uint64, uint float32, float64 complex64, complex128 byte rune string bool bool type represents a boolean. It can either be a true or false value. 1package main 2 3import "fmt" 4 5func main() { 6 a := true 7 b := false 8 fmt.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
This is the third tutorial in our Golang tutorial series and it deals with variables in Golang. You can read part 2 to learn about configuring Go and running the hello world program. What is a variable? Variable is the name given to a memory location to store a value of a specific type. There are various syntaxes to declare variables in Go. Let’s look at them one by one.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
This tutorial is now deprecated. Please visit /hello-world-gomod/ for the updated version. This is the second tutorial in our Golang tutorial series. Please read Golang tutorial part 1: Introduction and installation to know about what is golang and how to install golang. There is no better way to learn a programming language than getting our hands dirty with code. Lets go ahead and write our first go program. I would personally recommend using Visual Studio Code with the go extension as the IDE.| Go Tutorial - Learn Go from the Basics with Code Examples on golangbot.com
Go is one of the most popular server side programming languages created by Google. Go is a compiled language and it has a simple and concise syntax.| golangbot
A tutorial about WebAssembly and how to cross compile and run Go programs in the browser using WebAssembly.| golangbot