In this Getting Started with Golang, we will learn how to use the Golang Interfaces which is defined as a set of method signatures with step by step guide in Golang programming language.
#MaharlikansCode
#GolangInterfaces
#Golang
#LifeAsSoftwareDeveloper
#Maharlikans
#FilipinoSoftwareDeveloper
If you go with extra mile for buying me a cup of coffee, I appreciate it guys: https://ko-fi.com/maharlikanscode
Source Codes:
package main
import "fmt"
type calculator interface {
addition() float64
substraction() float64
multiplication() float64
}
type inputval struct {
num1, num2 float64
}
func (i inputval) addition() float64 {
return i.num1 + i.num2
}
func (i inputval) substraction() float64 {
return i.num1 - i.num2
}
func (i inputval) multiplication() float64 {
return i.num1 * i.num2
}
type calc calculator
// TP ...
type TP map[string]interface{}
func main() {
// Use the addition() method in calculator interface
i := inputval{2, 2}
c := calc.addition(i)
fmt.Println("addition result: ", c)
i = inputval{2, 2}
c = calc.substraction(i)
fmt.Println("substraction result: ", c)
tokenPayload := TP{
"API_KEY": "1223",
"USERNAME": "POL",
"ACTIVATION_KEY": "1DSF33KJJFSLS2",
}
fmt.Println("tokenPayload: ", tokenPayload)
for n, e := range tokenPayload {
if n == "API_KEY" {
fmt.Println("API KEY: ", e)
}
//fmt.Println("n: ", n, "e: ", e)
}
}