- Golang Web Api
- Web Scraping With Golang Windows 10
- Web Scraping With Golang Function
- Web Scraping With Golang Command
Lightning Fast and Elegant Scraping Framework for Gophers. Colly provides a clean interface to write any kind of crawler/scraper/spider. With Colly you can easily extract structured data from websites, which can be used for a wide range of applications, like data mining, data processing or archiving. Scraping & Parsing HTML (goquery) Golang mempunyai package net/html, isinya digunakan untuk keperluan parsing HTML. Pada bab ini kita akan belajar parsing HTML dengan cara yang lebih mudah, tidak memanfaatkan package net/html, melainkan menggunakan goquery.Library ini.
In general programming interfaces are contracts that have a set of functions to be implemented to fulfill that contract. Go is no different. Go has great support for interfaces and they are implemented in an implicit way. They allow polymorphism in Go. In this post, we will talk about interfaces, what they are, and how they can be used.
What is an Interface?
An interface is an abstract concept which enables polymorphism in Go. A variable of that interface can hold the value that implements the type. Type assertion is used to get the underlying concrete value as we will see in this post.
Declaring an interface in GoLang
An interface is declared as a type. Here is the declaration that is used to declare an interface.
type interfaceName interface{}
Zero-value of an interface
The zero value of an interface is nil. That means it holds no value and type. The code below shows that.
The empty interface in Go
An interface is empty if it has no functions at all. An empty interface holds any type. That’s why it is extremely useful in many cases. Below is the declaration of an empty interface.
var i interface{}
Implementing an interface in GoLang
An interface is implemented when the type has implemented the functions of the interface. Here is an example showing how to implement an interface.
Implementing multiple interfaces in Go
Multiple interfaces can be implemented at the same time. If all the functions are all implemented then the type implements all the interfaces. Below the type, the bird type implements both the interfaces by implementing the functions.
Composing interfaces together
Interfaces can be composed together. The composition is one of the most important concepts in software development. When multiple interfaces are implemented then the type has performed composition. This is really helpful where polymorphism is needed.
Values in an interface
Interface values have a concrete value and a dynamic type.
In the code above chirper is of type Bird but has a concrete value of {Chirpir}
.
Type assertion using the interface
Type assertion is a way to get the underlying value an interface holds. This means if an interface variable is assigned a string then the underlying value it holds is the string. Here is an example showing how to use type assertion using interfaces.
Type switch using an interface
Type switches are an extremely similar control structure like the switch-cases, the only difference is here the interface type is used to switch between different conditions.
Equality of interface values
The interface values can be equal if any of the conditions shown below are true.
- They both are nil.
- They have the same underlying concrete values and the same dynamic type.
Golang Web Api
Using interfaces with functions
Interfaces can be passed to functions just like any other type. Here is an example showing the usage of the interface with functions. A great advantage when using an interface is that it allows any type of argument as we can see in this code below.
Web Scraping With Golang Windows 10
Uses of an interface
Web Scraping With Golang Function
Interfaces are used in Go where polymorphism is needed. In a function where multiple types can be passed an interface can be used. Interfaces allow Go to have polymorphism.
Web Scraping With Golang Command
Interfaces are a great feature in Go and should be used wisely.