Posts
Hosting a web application and MySql database in a Docker container with Docker Compose
So far when ever I create an application and then use Docker, I run a Docker command that uses a DockerFile to create and image and then I have to spin up a new container for that image. But what I wanted was to be able to run a command and for my existing container to get the latest version of the code I was developing. That’s where I read about Docker Compose.
Posts
Creating Mysql databases in Docker
Recently I’ve been playing around with other databases other than Microsoft Sql Server. I’ve also been trying to use docker more, so to achieve both of these, I’ve been using new database images in Docker.
Prerequisites Docker using Linux containers
Mysql workbench
Create docker container with Mysql image docker run -p 3306:3306 -d --name {container name} -e MYSQL_ROOT_PASSWORD={password} mysql/mysql-server Check container is running docker ps Connect to the Mysql server inside container and create a new user docker exec -it {container name} bash mysql -uroot -p{password} (You’ll now be running the Mysql cli)
Posts
Interfaces in Go
Interfaces are a very useful part of software development as they allow the code to be decoupled. In Go, a language where there aren’t classes, we can use the structs and kind of use them as a class. That way we can create interfaces and then create structs that implement these interfaces.
Creating an interface in Go Creating an interface is quite easy.
type SomeService interface { DoSomething(string) string DoSomethingElse(int, string) string } Creating a struct and then making it implement the interface Next we create a struct, but instead of putting the functions from the interface inside the struct (because structs can only contain fields), we create the functions and then tell the functions what the receiver is.
Posts
Making HTTP requests and JSON decoding in Go
While creating a small command line app to make use of Azure’s translation services, I used the built in HTTP request package and the JSON decoding.
Making HTTP requests There are a few things required to make an HTTP call in Go. First, you need a client.
client := &http.Client{} You also need a url and if making a post request, a body in the form of JSON.
url := "http://localhost:80/something" body := strings.
Posts
Concurrency in Go
In Go, concurrency allows the application to do one thing while it’s waiting for something else to happen. So if one method is sleeping or waiting on a response from a service, then it can carry on and do something else in another function. This is done by using something called “Go Routines” which is Gos clever way of using a single thread and controlling which function or line of code uses this thread.
Posts
Go structs
This post will go through the use of Structs in Go and give an understanding of what they are used for.
What’s the point of Go structs? Let’s say the data types provided to us aren’t enough, and we want to create our own. Ones that have different properties of various types.
Imagine we have a person. This person has a name, age, occupation and height. Well we can create a struct that’s a person and then use this in our code.
Posts
Go variables
This post will go through the uses of variables in Go.
Creating a variable name := "will" This has created a variable called ’name’ and has the value “will”. Go knows that this is a string, so you don’t need to give it a type.
Changing the value of a variable If we want to change the value of a variable we do:
name = "someone else" Creating variables globally for the package If you want to create a few variables that are used in multiple functions within your package, you can declare them in a special way.
Posts
Introduction to Go
If you read my previous post, you’ll know that I’ve decided to take a dive into the world of Go and how to set up a dev environment to start programming in Go. Next I’m going to go into some of the basics of Go.
Basics So to start off, I’ll go through how a go file is constructed. Go is done in “Packages” or “Modules”. An application will have a “Main” package which will be what is run when the application is started.
Posts
Slices and Maps in Go
This post will go through the use of Slices and Maps in Go. (Is it me that always thinks of pizza when I hear slice!)
What’s a slice? In Go, a slice is a better array. It uses an array in the background to store the values, and the slice that you use in code, contains references to the array segments. This makes it lightweight and easier to manipulate.
An array has a fixed length, where as a slice can be increased and decreased in size if needed.
Posts
Setting up a Go dev environment
Today I decided to take a step away from the usual stuff I work with (.net, Angular) and learn something new. I have heard a few people tell me that Go is a fun and easy to pick up language and after a bit of Googling, I soon discovered how popular it was. So the next few blog posts will be Go related, starting with this post on setting up a dev environment.