Are you over 18 and want to see adult content?
More Annotations
A complete backup of https://audee.jp
Are you over 18 and want to see adult content?
A complete backup of https://krasota4u.ru
Are you over 18 and want to see adult content?
A complete backup of https://onzepropaganda.com.br
Are you over 18 and want to see adult content?
A complete backup of https://texas-wildlife.org
Are you over 18 and want to see adult content?
A complete backup of https://obdlink.com
Are you over 18 and want to see adult content?
A complete backup of https://sibcoin.org
Are you over 18 and want to see adult content?
A complete backup of https://bmglabtech.com
Are you over 18 and want to see adult content?
A complete backup of https://extratime.com
Are you over 18 and want to see adult content?
A complete backup of https://theparismarket.com
Are you over 18 and want to see adult content?
A complete backup of https://sillonbelge.be
Are you over 18 and want to see adult content?
A complete backup of https://coffeyville.com
Are you over 18 and want to see adult content?
A complete backup of https://semisonic.com
Are you over 18 and want to see adult content?
Favourite Annotations
Elektor - Learn, Design & Share electronics
Are you over 18 and want to see adult content?
ZonGuru – The Best All-in-One Toolset to Enlighten and Elevate your Amazon Business
Are you over 18 and want to see adult content?
A complete backup of kak-sdelatpravilno.ru
Are you over 18 and want to see adult content?
Zarif Tesettür - Tesettür Giyim Modası - Tesettür Alışveriş Sitesi
Are you over 18 and want to see adult content?
The Avocado – Home of the Austin Freaks
Are you over 18 and want to see adult content?
Largest Afghan Community - News, Map, Afghan Music, Afghan TV an much more | AfghanMania.com
Are you over 18 and want to see adult content?
Unión de Criadores de Toros de Lidia – Bienvenido a la UCTL
Are you over 18 and want to see adult content?
Text
example below.
CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you PRINT A VARIABLE'S TYPE (E.G. INT, STRING, FLOAT) · GOLANGCODE Ever wanted to know the exact type name of the variable you’re using? The Printf is capable of print exactly this information back out to you, like so: Alternatively, you can also use the reflect package. The TypeOf function will return a Type but we convert this to a string with .String (). TIMEOUT A FUNCTION CALL (WITH GOROUTINES & CHANNELS Some applications and programs can be very time sensitive - and they often need to return something in a timely fashion. However, it’s not always within our control to set a cut off point these operations. Go makes this process somewhat easier though through it’s use of goroutines and channels. In the example below we execute LongRunningProcess which we’ve given 3 seconds complete - but FIZZ-BUZZ TEST IN GO · GOLANGCODE A Library of Go Snippets. The fizzbuzz test is a simple program, often used in interviews to identify people who struggle to code.. The program should print the numbers from 1 to 100, except if the number is divisible by 3 then print ‘fizz’, if the number is divisible by 5 print ‘buzz’ or if the number if divisible by both print‘fizzbuzz’.
PARSING DATES FROM A STRING AND FORMATTING · GOLANGCODE The parse function is interesting because, unlike some programming languages, to parse a date you don’t specify the date using letters (Y-m-d for example). Instead you use a real time as the format - this time in fact: 2006-01-02T15:04:05+07:00. Some existing date constants include: To use the MySQL date format, you’d use: “2006-01-02 15 FOREACH LOOPS: THE GO WAY · GOLANGCODE The foreach keyword itself does not exist within Go, instead the for loop can be adapted to work in the same manner. The difference however, is by using the range keyword and a for loop together. Like foreach loops in many other languages you have the choice of using the slices’ key or value within the loop. Example 1) In our example, we iterate over a string slice and print out each word. GO GET: INSTALL ALL PACKAGES · GOLANGCODE The answer is to use go get within the current project and tell it to find all required packages recursively by using this command: (We’re including the -u parameter to also update any existing packages.) If you’re want to see what’s happening with this command, as it’s a quiet command, the add the -v parameter to add a layer of verbosity. BUILD A BASIC WEB SCRAPER IN GO · GOLANGCODE This is a single page web scraper, it uses the goquery library to parse the html and allow it to be queried easily (like jQuery). There is a Find method we can use to query for classes and ids in same way as a css selector. In our example we use this to get the latest blog titles from golangcode. If you needed to search an entire site, you could implement a query to follow and recall a link urls. BASIC GO ROUTINES (LIKE THREADING) · GOLANGCODE This script basically just prints out the numbers 1 to 10, but it does so by spinning off each print statement into it’s own thread, using a go routine. You’ll notice the script also has a start and an end print statement, but because go routines are used, the end statement will be printed before and items (1-10) are printed. The ending sleep allows the go routines to execute as they were HOW TO RUN A SINGLE TEST · GOLANGCODE Go has a simple command line for running its tests, with go test. However, often when writing tests you don’t care about the rest of the test suite - you just want to run your new test. This post shows you the command you need to run just your test, as well as a fullexample below.
CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you PRINT A VARIABLE'S TYPE (E.G. INT, STRING, FLOAT) · GOLANGCODE Ever wanted to know the exact type name of the variable you’re using? The Printf is capable of print exactly this information back out to you, like so: Alternatively, you can also use the reflect package. The TypeOf function will return a Type but we convert this to a string with .String (). TIMEOUT A FUNCTION CALL (WITH GOROUTINES & CHANNELS Some applications and programs can be very time sensitive - and they often need to return something in a timely fashion. However, it’s not always within our control to set a cut off point these operations. Go makes this process somewhat easier though through it’s use of goroutines and channels. In the example below we execute LongRunningProcess which we’ve given 3 seconds complete - but FIZZ-BUZZ TEST IN GO · GOLANGCODE A Library of Go Snippets. The fizzbuzz test is a simple program, often used in interviews to identify people who struggle to code.. The program should print the numbers from 1 to 100, except if the number is divisible by 3 then print ‘fizz’, if the number is divisible by 5 print ‘buzz’ or if the number if divisible by both print‘fizzbuzz’.
PARSING DATES FROM A STRING AND FORMATTING · GOLANGCODE The parse function is interesting because, unlike some programming languages, to parse a date you don’t specify the date using letters (Y-m-d for example). Instead you use a real time as the format - this time in fact: 2006-01-02T15:04:05+07:00. Some existing date constants include: To use the MySQL date format, you’d use: “2006-01-02 15 GOLANGCODE - A LIBRARY OF GO SNIPPETS We can achieve this in Go through the use of interfaces and creating a “mock” uploader when our tests run. Below we’ve build an example to show this, first showing the test and then the code it’s testing. Argon2 is a password hashing algorithm which was voted the winner in the Password Hashing Competition in 2015. GO GET: INSTALL ALL PACKAGES · GOLANGCODE The answer is to use go get within the current project and tell it to find all required packages recursively by using this command: (We’re including the -u parameter to also update any existing packages.) If you’re want to see what’s happening with this command, as it’s a quiet command, the add the -v parameter to add a layer of verbosity. BUILD A BASIC WEB SCRAPER IN GO · GOLANGCODE This is a single page web scraper, it uses the goquery library to parse the html and allow it to be queried easily (like jQuery). There is a Find method we can use to query for classes and ids in same way as a css selector. In our example we use this to get the latest blog titles from golangcode. If you needed to search an entire site, you could implement a query to follow and recall a link urls. READ A FILE TO STRING · GOLANGCODE This is a matching post to “Writing to a File” and explains how to simply get the contents of a file as text and print it to screen. There are different ways to achieve this in Go - all valid. In this guide though we’ve gone for the simple approach. Using ioutil makes this easy for us by not having to worry about closing files or using buffers. At the cost though of not having CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and youSLEEPING IN GO
Sleeping, or waiting in Go, is part of the time package.It’s a very simple process, all you need to do is specify the duration to sleep for, which in this case is a number followed by it’s unit, so 2*time.Second means 2 seconds. This will sleep the current goroutine so other go routines will continue to CREATE ZIP FILES IN GO · GOLANGCODE The code below shows how you can create a zip archive after being passed a number of files to compress. This is useful for both bundling files together and creating smaller file sizes. The basics of it are to create the initial zip file then cycle through each file and add it to the archive using a zip writer, being sure to specify the deflate method to get better compression. IS LONG/LAT WITHIN POLYGON FROM GEOJSON · GOLANGCODE This is an example of checking if a pair of long/lat coordinates lie within a polygon or multipolygon when working with geojson. It’s often useful when working with geo-special data and maps to determine if the point your looking is within an area - or which area it’s within. We use the paulmach/orb package (see on github), which is deep and precise library for dealing with all sorts of CONVERT IO.READCLOSER TO A STRING · GOLANGCODE Net/http is an amazing package but there are times you need to work with the body text of the response returned from the call you just made. Many functions require a string as input so we have to convert it first by passing it through a buffer. ADD LINE NUMBERS TO LOG OUTPUT · GOLANGCODE Many programming languages allow you to print the line number of when and where something has happened. This is very useful for debugging aproblem when it has
GO GET: INSTALL ALL PACKAGES · GOLANGCODE The answer is to use go get within the current project and tell it to find all required packages recursively by using this command: (We’re including the -u parameter to also update any existing packages.) If you’re want to see what’s happening with this command, as it’s a quiet command, the add the -v parameter to add a layer of verbosity. FOREACH LOOPS: THE GO WAY · GOLANGCODE The foreach keyword itself does not exist within Go, instead the for loop can be adapted to work in the same manner. The difference however, is by using the range keyword and a for loop together. Like foreach loops in many other languages you have the choice of using the slices’ key or value within the loop. Example 1) In our example, we iterate over a string slice and print out each word. BASIC GO ROUTINES (LIKE THREADING) · GOLANGCODE This script basically just prints out the numbers 1 to 10, but it does so by spinning off each print statement into it’s own thread, using a go routine. You’ll notice the script also has a start and an end print statement, but because go routines are used, the end statement will be printed before and items (1-10) are printed. The ending sleep allows the go routines to execute as they were HOW TO RUN A SINGLE TEST · GOLANGCODE Go has a simple command line for running its tests, with go test. However, often when writing tests you don’t care about the rest of the test suite - you just want to run your new test. This post shows you the command you need to run just your test, as well as a fullexample below.
CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you PRINT A VARIABLE'S TYPE (E.G. INT, STRING, FLOAT) · GOLANGCODE Ever wanted to know the exact type name of the variable you’re using? The Printf is capable of print exactly this information back out to you, like so: Alternatively, you can also use the reflect package. The TypeOf function will return a Type but we convert this to a string with .String (). JSON WEB TOKENS: AUTHENTICATING YOUR API · GOLANGCODE There are of course many different ways to build authentication into APIs these days - JSON web tokens being just one of them. JSON Web Tokens (JWT) have an inherent advantage over other methods, like Basic Authentication, by working as a token system instead of sending the username and password with every request. To learn more about it, head over to the introduction on jwt.io before we FIZZ-BUZZ TEST IN GO · GOLANGCODE A Library of Go Snippets. The fizzbuzz test is a simple program, often used in interviews to identify people who struggle to code.. The program should print the numbers from 1 to 100, except if the number is divisible by 3 then print ‘fizz’, if the number is divisible by 5 print ‘buzz’ or if the number if divisible by both print‘fizzbuzz’.
PARSING DATES FROM A STRING AND FORMATTING · GOLANGCODE The parse function is interesting because, unlike some programming languages, to parse a date you don’t specify the date using letters (Y-m-d for example). Instead you use a real time as the format - this time in fact: 2006-01-02T15:04:05+07:00. Some existing date constants include: To use the MySQL date format, you’d use: “2006-01-02 15 ADD LINE NUMBERS TO LOG OUTPUT · GOLANGCODE Many programming languages allow you to print the line number of when and where something has happened. This is very useful for debugging aproblem when it has
GO GET: INSTALL ALL PACKAGES · GOLANGCODE The answer is to use go get within the current project and tell it to find all required packages recursively by using this command: (We’re including the -u parameter to also update any existing packages.) If you’re want to see what’s happening with this command, as it’s a quiet command, the add the -v parameter to add a layer of verbosity. FOREACH LOOPS: THE GO WAY · GOLANGCODE The foreach keyword itself does not exist within Go, instead the for loop can be adapted to work in the same manner. The difference however, is by using the range keyword and a for loop together. Like foreach loops in many other languages you have the choice of using the slices’ key or value within the loop. Example 1) In our example, we iterate over a string slice and print out each word. BASIC GO ROUTINES (LIKE THREADING) · GOLANGCODE This script basically just prints out the numbers 1 to 10, but it does so by spinning off each print statement into it’s own thread, using a go routine. You’ll notice the script also has a start and an end print statement, but because go routines are used, the end statement will be printed before and items (1-10) are printed. The ending sleep allows the go routines to execute as they were HOW TO RUN A SINGLE TEST · GOLANGCODE Go has a simple command line for running its tests, with go test. However, often when writing tests you don’t care about the rest of the test suite - you just want to run your new test. This post shows you the command you need to run just your test, as well as a fullexample below.
PRINT A VARIABLE'S TYPE (E.G. INT, STRING, FLOAT) · GOLANGCODE Ever wanted to know the exact type name of the variable you’re using? The Printf is capable of print exactly this information back out to you, like so: Alternatively, you can also use the reflect package. The TypeOf function will return a Type but we convert this to a string with .String (). CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you JSON WEB TOKENS: AUTHENTICATING YOUR API · GOLANGCODE There are of course many different ways to build authentication into APIs these days - JSON web tokens being just one of them. JSON Web Tokens (JWT) have an inherent advantage over other methods, like Basic Authentication, by working as a token system instead of sending the username and password with every request. To learn more about it, head over to the introduction on jwt.io before we FIZZ-BUZZ TEST IN GO · GOLANGCODE A Library of Go Snippets. The fizzbuzz test is a simple program, often used in interviews to identify people who struggle to code.. The program should print the numbers from 1 to 100, except if the number is divisible by 3 then print ‘fizz’, if the number is divisible by 5 print ‘buzz’ or if the number if divisible by both print‘fizzbuzz’.
PARSING DATES FROM A STRING AND FORMATTING · GOLANGCODE A Library of Go Snippets. We almost touched on this in our post about unix time - but in this post we look at how to take an arbitrary date in string format and convert it into a meaningful date in the format we want. This uses two important functions, Parse and Format within the time package. The parse function is interesting because, unlike some programming languages, to parse a date you don ADD LINE NUMBERS TO LOG OUTPUT · GOLANGCODE Many programming languages allow you to print the line number of when and where something has happened. This is very useful for debugging aproblem when it has
GOLANGCODE - A LIBRARY OF GO SNIPPETS We can achieve this in Go through the use of interfaces and creating a “mock” uploader when our tests run. Below we’ve build an example to show this, first showing the test and then the code it’s testing. Argon2 is a password hashing algorithm which was voted the winner in the Password Hashing Competition in 2015. BUILD A BASIC WEB SCRAPER IN GO · GOLANGCODE This is a single page web scraper, it uses the goquery library to parse the html and allow it to be queried easily (like jQuery). There is a Find method we can use to query for classes and ids in same way as a css selector. In our example we use this to get the latest blog titles from golangcode. If you needed to search an entire site, you could implement a query to follow and recall a link urls. CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you HTTP RESPONSE STATUS CODES · GOLANGCODE HTTP Response Status Codes. When making http requests with Go it is almost always necessary to check the status code of the response which is returned. Generally, if the status code is between 200 and 300 you can treat as successful. But anything except a 200-300 status, we often need to handle. Go has many built methods to help us with this. PARSING DATES FROM A STRING AND FORMATTING · GOLANGCODE A Library of Go Snippets. We almost touched on this in our post about unix time - but in this post we look at how to take an arbitrary date in string format and convert it into a meaningful date in the format we want. This uses two important functions, Parse and Format within the time package. The parse function is interesting because, unlike some programming languages, to parse a date you donSLEEPING IN GO
Sleeping, or waiting in Go, is part of the time package.It’s a very simple process, all you need to do is specify the duration to sleep for, which in this case is a number followed by it’s unit, so 2*time.Second means 2 seconds. This will sleep the current goroutine so other go routines will continue to GET THE CURRENT USERNAME, NAME AND HOME DIR (CROSS In this example we get the current user, the user who is executing the program, and their details. These details include information like user id (Uid), username (the short version of their name), name (the user’s full name) and the user’s home directory location. To do this we use the os/user package. This package also handles the differences between OS like *nix vs. windows very well PRINT THE CURRENT MEMORY USAGE · GOLANGCODE The program below is designed to print out the current state of how much memory is being used, how much has been used and how much the system has reserved. You only really need the PrintMemUsage() function to do this, the rest of the main() is there to illustrate it working (with a gif showing this at the end of this post). The most important figure if often the Alloc which is the amount ADD LINE NUMBERS TO LOG OUTPUT · GOLANGCODE Many programming languages allow you to print the line number of when and where something has happened. This is very useful for debugging aproblem when it has
CONVERT IO.READCLOSER TO A STRING · GOLANGCODE Net/http is an amazing package but there are times you need to work with the body text of the response returned from the call you just made. Many functions require a string as input so we have to convert it first by passing it through a buffer. GOLANGCODE - A LIBRARY OF GO SNIPPETS A Library of Go Snippets. Validating an Email Address . Validating email addresses, like many thing, are one of those things you can put any amount of effort you want into. GO GET: INSTALL ALL PACKAGES · GOLANGCODE The answer is to use go get within the current project and tell it to find all required packages recursively by using this command:. go get -u ./ (We’re including the -u parameter to also update any existing packages.). If you’re want to see what’s happening with this command, as it’s a quiet command, the add the -v parameter to add alayer of verbosity.
BASIC GO ROUTINES (LIKE THREADING) · GOLANGCODE This script basically just prints out the numbers 1 to 10, but it does so by spinning off each print statement into it’s own thread, using a go routine. You’ll notice the script also has a start and an end print statement, but because go routines are used, the end statement will be printed before and items (1-10) are printed. The ending sleep allows the go routines to execute as they were FOREACH LOOPS: THE GO WAY · GOLANGCODE The foreach keyword itself does not exist within Go, instead the for loop can be adapted to work in the same manner. The difference however, is by using the range keyword and a for loop together. Like foreach loops in many other languages you have the choice of using the slices’ key or value within the loop. Example 1) In our example, we iterate over a string slice and print out each word. BUILD A BASIC WEB SCRAPER IN GO · GOLANGCODE This is a single page web scraper, it uses the goquery library to parse the html and allow it to be queried easily (like jQuery). There is a Find method we can use to query for classes and ids in same way as a css selector. In our example we use this to get the latest blog titles from golangcode. If you needed to search an entire site, you could implement a query to follow and recall a link urls. JSON WEB TOKENS: AUTHENTICATING YOUR API · GOLANGCODE There are of course many different ways to build authentication into APIs these days - JSON web tokens being just one of them. JSON Web Tokens (JWT) have an inherent advantage over other methods, like Basic Authentication, by working as a token system instead of sending the username and password with every request. To learn more about it, head over to the introduction on jwt.io before we HTTP RESPONSE STATUS CODES · GOLANGCODE When making http requests with Go it is almost always necessary to check the status code of the response which is returned. Generally, if the status code is between 200 and 300 you can treat as successful. But anything except a 200-300 status, we often need to handle. Go has many built methods to help us with this. For example, we can use http.StatusText() to convert the status code to it’s CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you HOW TO CHECK IF A STRING STARTS WITH · GOLANGCODE In this post we look at how to check if a given string starts with something. This is often used in programming and there are different ways to achieve the same goal. We provide two options in this example. The first is to use the strings package along with the HasPrefix function - this is probably the simplest/best solution. We did include a second option though, if you know how long the PRINT A VARIABLE'S TYPE (E.G. INT, STRING, FLOAT) · GOLANGCODE Author: Edd Turtle. Edd is the Lead Developer at Hoowla, a prop-tech startup, where he spends much of his time working on production-readyGo and PHP code.
GOLANGCODE - A LIBRARY OF GO SNIPPETS A Library of Go Snippets. Validating an Email Address . Validating email addresses, like many thing, are one of those things you can put any amount of effort you want into. GO GET: INSTALL ALL PACKAGES · GOLANGCODE The answer is to use go get within the current project and tell it to find all required packages recursively by using this command:. go get -u ./ (We’re including the -u parameter to also update any existing packages.). If you’re want to see what’s happening with this command, as it’s a quiet command, the add the -v parameter to add alayer of verbosity.
BASIC GO ROUTINES (LIKE THREADING) · GOLANGCODE This script basically just prints out the numbers 1 to 10, but it does so by spinning off each print statement into it’s own thread, using a go routine. You’ll notice the script also has a start and an end print statement, but because go routines are used, the end statement will be printed before and items (1-10) are printed. The ending sleep allows the go routines to execute as they were FOREACH LOOPS: THE GO WAY · GOLANGCODE The foreach keyword itself does not exist within Go, instead the for loop can be adapted to work in the same manner. The difference however, is by using the range keyword and a for loop together. Like foreach loops in many other languages you have the choice of using the slices’ key or value within the loop. Example 1) In our example, we iterate over a string slice and print out each word. BUILD A BASIC WEB SCRAPER IN GO · GOLANGCODE This is a single page web scraper, it uses the goquery library to parse the html and allow it to be queried easily (like jQuery). There is a Find method we can use to query for classes and ids in same way as a css selector. In our example we use this to get the latest blog titles from golangcode. If you needed to search an entire site, you could implement a query to follow and recall a link urls. JSON WEB TOKENS: AUTHENTICATING YOUR API · GOLANGCODE There are of course many different ways to build authentication into APIs these days - JSON web tokens being just one of them. JSON Web Tokens (JWT) have an inherent advantage over other methods, like Basic Authentication, by working as a token system instead of sending the username and password with every request. To learn more about it, head over to the introduction on jwt.io before we HTTP RESPONSE STATUS CODES · GOLANGCODE When making http requests with Go it is almost always necessary to check the status code of the response which is returned. Generally, if the status code is between 200 and 300 you can treat as successful. But anything except a 200-300 status, we often need to handle. Go has many built methods to help us with this. For example, we can use http.StatusText() to convert the status code to it’s CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you HOW TO CHECK IF A STRING STARTS WITH · GOLANGCODE In this post we look at how to check if a given string starts with something. This is often used in programming and there are different ways to achieve the same goal. We provide two options in this example. The first is to use the strings package along with the HasPrefix function - this is probably the simplest/best solution. We did include a second option though, if you know how long the PRINT A VARIABLE'S TYPE (E.G. INT, STRING, FLOAT) · GOLANGCODE Author: Edd Turtle. Edd is the Lead Developer at Hoowla, a prop-tech startup, where he spends much of his time working on production-readyGo and PHP code.
BUILD A BASIC WEB SCRAPER IN GO · GOLANGCODE This is a single page web scraper, it uses the goquery library to parse the html and allow it to be queried easily (like jQuery). There is a Find method we can use to query for classes and ids in same way as a css selector. In our example we use this to get the latest blog titles from golangcode. If you needed to search an entire site, you could implement a query to follow and recall a link urls. BASIC GO ROUTINES (LIKE THREADING) · GOLANGCODE This script basically just prints out the numbers 1 to 10, but it does so by spinning off each print statement into it’s own thread, using a go routine. You’ll notice the script also has a start and an end print statement, but because go routines are used, the end statement will be printed before and items (1-10) are printed. The ending sleep allows the go routines to execute as they were HOW TO RUN A SINGLE TEST · GOLANGCODE Go has a simple command line for running its tests, with go test. However, often when writing tests you don’t care about the rest of the test suite - you just want to run your new test. This post shows you the command you need to run just your test, as well as a fullexample below.
CHECK ELEMENT EXISTS IN A SLICE · GOLANGCODE Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you HOW TO CHECK IF A STRING STARTS WITH · GOLANGCODE In this post we look at how to check if a given string starts with something. This is often used in programming and there are different ways to achieve the same goal. We provide two options in this example. The first is to use the strings package along with the HasPrefix function - this is probably the simplest/best solution. We did include a second option though, if you know how long the GET A URL PARAMETER FROM A REQUEST · GOLANGCODE Often it’s important to read off the parameters sent through from the request. If it’s a GET request these will lie within the url itself and can be read using the request’s URL property. It’s important to note that when getting the parameters in this way it will always return an array (or slice?). Our example below will act a little like an echo server, we listen for any requests andSLEEPING IN GO
Sleeping, or waiting in Go, is part of the time package.It’s a very simple process, all you need to do is specify the duration to sleep for, which in this case is a number followed by it’s unit, so 2*time.Second means 2 seconds. This will sleep the current goroutine so other go routines will continue to HOW TO: HANDLE ERRORS WITHIN WAIT GROUPS · GOLANGCODE One of the many benefits of using Go is it’s simplicity when it comes to concurrency. With WaitGroups being an excellent example of this. It can be tricky though to handle both concurrency and errors effectively. This post aims to outline how you can run multiple goroutines and handle any errors effectively, without stopping program execution. The essence of this comes down to these three PRINT A VARIABLE'S TYPE (E.G. INT, STRING, FLOAT) · GOLANGCODE Author: Edd Turtle. Edd is the Lead Developer at Hoowla, a prop-tech startup, where he spends much of his time working on production-readyGo and PHP code.
ADD LINE NUMBERS TO LOG OUTPUT · GOLANGCODE Many programming languages allow you to print the line number of when and where something has happened. This is very useful for debugging aproblem when it has
Tags About
__ Search
Subscribe
Drive
deeper customer connections with Mailchimp's marketing CRM.ads
via Carbon
GOLANG CODE
A LIBRARY OF GO SNIPPETSSearch
* JSON Web Tokens: Authenticating your API There are of course many different ways to build authentication into APIs these days - JSON web tokens being just one of them. JSON Web Tokens (JWT) have an inherent advantage over other methods, like Basic Authentication, by working as a token system instead of sending the username and password with every request. To learn more about it, head over to the introduction on jwt.io before we dive straight into it.#json #web token
#jwt
#auth
#api
#key
#signed
#token
#handler
#middleware
* Check Element Exists in a Slice Go doesn’t have a find or in_array function as part of it’s standard library. They are easy to create however. In this example we create a Find() function to search a slice of strings for the element we are looking for. Cue the “generics” rant from some coders. This is a great example of why they could be useful. We have created our find function, but it only works with strings and you will have to create different find functions for different types - as needed.#find #slice
#map
#element
#generics
#key
#index
#item
#contains
* Read a File to String This is a matching post to “Writing to a File” and explains how to simply get the contents of a file as text and print it to screen. There are different ways to achieve this in Go - all valid. In this guide though we’ve gone for the simple approach. Using ioutil makes this easy for us by not having to worry about closing files or using buffers. At the cost though of not having flexibility over which parts of the file we need.#file #read
#content
#text
#string
#ioutil
#open
#buffer
#reading
* Timeout a Function Call (with Goroutines & Channels) Some applications and programs can be very time sensitive - and they often need to return something in a timely fashion. However, it’s not always within our control to set a cut off point these operations. Go makes this process somewhat easier though through it’s use of goroutines and channels. In the example below we execute LongRunningProcess which we’ve given 3 seconds complete - but it contains code to sleep for 5, so it will never complete. #goroutine #channel#timeout
#time
#seconds
#select
#after
#kill
#execution
* Find Common Colours in an Image This is part 1 of how to find the dominant colours within an image. You might spot this functionality around the internet, as it’s used to give images background colours before the image has loaded. We use a package to do this - which manages much of the heavy lifting. The package, called prominentcolor, uses the Kmeans++ algorithm to work this out. By default, it will return us the three most popular colours after both cropping and resizing the image.#image #color
#colours
#common
#dominant
#kmeans
#crop
#library
* How to Check If a String Starts With ... In this post we look at how to check if a given string starts with something. This is often used in programming and there are different ways to achieve the same goal. We provide two options in this example. The first is to use the strings package along with the HasPrefix function - this is probably the simplest/best solution. We did include a second option though, if you know how long the prefix that you’re looking for is, you can use the string as a slice and check it’svalue.
#string #prefix
#starts
#slice
#length
#hasprefix
* Working with POST Request Data This is an overview post (pun intended) about how to work with post request data sent to an endpoint via HTTP. This is slightly different to data stored in query parameters sent in the url and has to be handled differently. Because we’re using a http server, we can parse the request (in variable r) using ParseForm() and then use the data from the map generated. This will only work with data sent with a Content-Type header of application/x-www-form-urlencode or multipart/form-data.#http #post
#request
#data
#form
#param
#contenttype
#parse
* Go Get: Install All Packages Go has a simple built in way to download packages. If you’ve programmed in Go, you’ve likely used the go get command before (view docs). It often works something like this: go get -u github.com/gorilla/mux Which is great - but! What if you want to download all the packages linked to your project? This commonly happens if you pull a new project down using version control and don’t want to go get each package individually.#command #install
#goget
#packages
#cmd
#project
#update
#verbose
* Sublime Text Workflow: Auto Build & Format Sublime Text 3 can be a great editor for writing Go code - and with a few simple tweaks it can get better. One example of a simple workflow improvement to automate the running of go fmt each time you save. This keeps your code neat and tidy, while also alerting you to any syntax errors. Some things you’ll need to get started: Go installed (with a GOPATH) Sublime Text Installed 1) Install Package Control Firstly, we’ll install Sublime’s Package Control by going to their site:packagecontrol.
#sublime #workflow
#automate
#build
#fmt
#format
#plugin
* JSON Encode - Pretty Print Is JSON for computers or humans to read? Well, hopefully with this snippet it can be for both. Instead of just dumping all the json in one line, we instead format it and indent it for readability purposes. Using the MarshalIndent function in the json package we’re able to not only specify the data to encode, but also a prefix and an indentation string. In our example we’re not to worried about the prefix, but the indentation (3rd parameter) allows us to structure ourcode.
#json #encode
#pretty
#readable
#format
#indent
#prefix
#marshal
Older Posts →
__ __ __
Code shown Licenced under MIT LicencePrivacy Policy
Copyright 2019 __ Designed by a TurtleDetails
Copyright © 2024 ArchiveBay.com. All rights reserved. Terms of Use | Privacy Policy | DMCA | 2021 | Feedback | Advertising | RSS 2.0