张 小龙

1599281100

How to Error Handling in Go Programs

In this post we’re going to share some lessons we’ve learned while using Go in production for several years here at Gravitational.

Intro

Go does not have exceptions, rather error handling is done by checking errors. This requires some adjustments in how you deal with errors if you are coming from languages that have exceptions as a primary error handling mechanism.

Dave Cheney wrote a series of articles going deeper into better ways to handle errors in Go, which I highly recommend reading.

Here are some tips and solutions that helped me to improve error handling in Go applications:

#go #golang

What is GEEK

Buddha Community

How to Error Handling in Go Programs
Fannie  Zemlak

Fannie Zemlak

1599854400

What's new in the go 1.15

Go announced Go 1.15 version on 11 Aug 2020. Highlighted updates and features include Substantial improvements to the Go linker, Improved allocation for small objects at high core counts, X.509 CommonName deprecation, GOPROXY supports skipping proxies that return errors, New embedded tzdata package, Several Core Library improvements and more.

As Go promise for maintaining backward compatibility. After upgrading to the latest Go 1.15 version, almost all existing Golang applications or programs continue to compile and run as older Golang version.

#go #golang #go 1.15 #go features #go improvement #go package #go new features

Biju Augustian

Biju Augustian

1574341105

Python Programming & Data Handling

Description
Students will be able to know various commands include:

Python Basic Programming

string,if else,Range, for loop, while loop, making functions, tuple, dictionary etc

WEB WORKING:

Download files from Web, Exceptional Handling etc

Data Handling:

Get data from files create , read, write, delete.

IMAGE PROCESSING: (NEW DEVELOPING ART)

Image transformation , Image crop , edit and much more

Basic knowledge
Listener should know how about very basic C Language basic commands to understand Python Language
What will you learn
I will more update if any student want need to add more skills related to python

#Python Programming & Data Handling #Python Programming #Data Handling #Programming # Python

Zander  Herzog

Zander Herzog

1596793260

Secure HTTPS servers in Go

In this article, we are going to look at some of the basic APIs of the http package to create and initialize HTTPS servers in Go.

Image for post

(source: unsplash.com)

In the “Simple Hello World Server” lesson, we learned about net/http package, how to create routes and how [ServeMux](https://golang.org/pkg/net/http/#ServeMux) works. In the “Running multiple HTTP servers” lesson, we learned about [Server](https://golang.org/pkg/net/http/#Server) structure and how to run multiple HTTP servers concurrently.

In this lesson, we are going to create an HTTPS server using both Go’s standard server configuration and custom configuration (using [_Server_](https://golang.org/pkg/net/http/#Server) structure). But before this, we need to know what HTTPS really is?

HTTPS is a big topic of discussion in itself. Hence while writing this lesson, I published an article just on “How HTTPS works?”. I advise you to read this lesson first before continuing this article. In this article, I’ve also described the encryption paradigm and SSL certificates generation process.


If we recall the simplest HTTP server example from previous lessons, we only need http.``[ListenAndServe](https://golang.org/pkg/net/http/#ListenAndServe) function to start an HTTP server and http.``[HandleFunc](https://golang.org/pkg/net/http/#HandleFunc) to register a response handler for a particular endpoint.

Image for post

(https://play.golang.org/p/t3sOenOYAzS)

In the example above, when we run the command go run server.go , it will start an HTTP server on port 9000. By visiting http://localhost:9000 URL in a browser, you will be able to see a Hello World! message on the screen.

Image for post

(http://localhost:9000)

As we know, the nil argument to ListenAndServe() call invokes Go to use the [DefaultServeMux](https://golang.org/pkg/net/http/#DefaultServeMux) response multiplexer, which is the default instance of ServeMux structure provided globally by the Go. The HandleFunc() call adds a response handler for a specific route on the multiplexer instance.

The http.ListenAndServe() call uses the Go’s standard HTTP server configuration, however, in the previous lesson, how we can customize a server using [Server](https://golang.org/pkg/net/http/#Server) structure type.

To start an HTTPS server, all we need do is to call ServerAndListenTLS method with some configuration. Just like ServeAndListen method, this method is available on both the http package and the Server structure.

The http.``[ServeAndListenTLS](https://golang.org/pkg/net/http/#ListenAndServeTLS) method uses the Go’s standard server implementation, however, both [Server](https://golang.org/pkg/net/http/#Server) instance and Server.``[ServeAndListenTLS](https://golang.org/pkg/net/http/#Server.ListenAndServeTLS) method can be configured for our needs.

#go-programming-language #go #golang-tutorial #go-programming #golang

Roberta  Ward

Roberta Ward

1593369360

Advanced Error Handling in Swift 5

In Swift, there are many ways to handle errors. In this article, I am going to deeply explain how to handle errors using throwable functions.
If you are familiar with JSONDecoder(), then you have seen the below code before.
do {
try JSONDecoder().decode(MyStruct.self, from: someData)
} catch let error {
print(error)
}
This is called Do-Catch block, where we are forced to use it otherwise Xcode will complain and won’t compile and gives us this error:
“Call can throw, but it is not marked with ‘try’ and the error is not handled”
That’s because the method decode(_:) is a throwable which means it might throw an error and we can’t handle it like a normal function.
To have a better understanding of the difference between try, try!, and try? let’s design our own throwable method.
Say we have to design a system that allows people to ride a Roller Coaster and our requirements are that the rider cannot be shorter than 120 cm and not taller than 210 cm.
First thing we do we need to write an enum and conform it to the Error protocol.
enum RiderHeightError: Error {
case tooShortToRide
case tooTallToRide
}
Then let’s create a computed property that describes our error cases.
enum RiderHeightError: Error {

case tooShortToRide
case tooTallToRide
var description: String {
    switch self {
    case .tooShortToRide:
        return "You are shorter than 120 cm, try next year."
    case .tooTallToRide:
        return "You are taller than 210 cm, try another game."
    }
}

}
Now we have our enum with the error cases ready, let’s write a throwable function.
func safetyCheck(riderHeight: Int) throws {

if riderHeight < 120 {

    throw RiderHeightError.tooShortToRide

} else if riderHeight > 210 {
    throw RiderHeightError.tooTallToRide
} else {
    print("You are good to go. Have fun.")
}

}
Now we’ve created a function called safetyCheck(). It has one parameter which is the rider’s height. The function checks twice on the rider’s height to make sure it complies with the safety rules.
You noticed that we used two new keywords “throws” and “throw”. The difference between both is pretty simple.
“throws” means this function is throwable and in order to use it, you have to write try before the function.
“throw” means that something went wrong and a specific error has to be thrown.
Basically there are three ways to call a throwable function.
First way is to write Do-Catch block which is the recommended way to handle the errors.
do {
try safetyCheck(riderHeight: 110)
} catch let riderError {
if let error = riderError as? RiderHeightError {
print(error.description)
}
}
=> You are shorter than 120 cm, try next year.
We see that we caught the error and we also got a clear description of the error. There are many ways to write the catch block. The next example I’ll show another way to do it.
do {
try safetyCheck(riderHeight: 230)
} catch RiderHeightError.tooShortToRide {
print(“Too Short To Ride The Roller Coaster”)
} catch RiderHeightError.tooTallToRide {

print("Too Tall To Ride The Roller Coaster")

}
=> Too Tall To Ride The Roller Coaster
Second way is to use “try?” instead of Do-Catch block. It will reduce a few lines of code, but it won’t give you what exactly went wrong. It will give you nil instead if an error was thrown.
try? safetyCheck(riderHeight: 100)
=> nil

#swift-programming #swift #error #error-handling #ios-app-development #ios

Learning Go — Array, Slice, Map

We have already seen how to create and work with variables, pointers, and Constants. In this article, we are going to see the four important collection types built into the language.
We start with humble Arrays, from there we move on to Slice, an evolved version of Array. From Slice, we talk about the map a key-value pair collection. Let’s start with Arrays here.

#golang-tutorial #golang #go-programming #go-programming-language #programming