This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"fmt" | |
) | |
func main() { | |
err := errors.New("it's an error") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
// The error built-in interface type is the conventional interface | |
// for representing an error condition, with the nil value | |
// representing no error. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package errors | |
// New returns an error that formats as the given text. | |
// Each call to New returns a distinct error value even if the text is identical. | |
func New(text string) error { | |
return &errorString{text} | |
} | |
// errorString is a trivial implementation of error. | |
type errorString struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
//Area function to calculate Area of Rectangle | |
func Area(length int, breadth int) int { | |
return length * breadth | |
} | |
//Area function to calculate Area of Square |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/sagar23sj/Go-OOP/Encapsulation/animal" | |
) | |
func main() { | |
//Creating an object of type Dog from animal package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package animal | |
//Unexported type struct | |
type animal struct { | |
Name string | |
} | |
//Exported type Dog embedding type Animal | |
type Dog struct { | |
animal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package animal | |
//Exported type struct | |
type Animal struct { | |
Name string | |
} | |
//Exported type Dog embedding type Animal | |
type Dog struct { | |
Animal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package employee | |
//Exported struct type Employee with employee details | |
type Employee struct { | |
Name string | |
Age int | |
salary float64 | |
} | |
func (e *Employee) SetSalary(val float64) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package employee | |
//Exported struct type Employee with employee details | |
type Employee struct { | |
Name string | |
Age int | |
salary float64 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package counter | |
// internalCounter is an unexported identifier of integer type | |
type internalCounter int | |
// NewInternalCounter creates an object of internalCounter | |
// with value passed to it and returns | |
// an object of type internalCounter | |
func NewInternalCounter(val int) internalCounter { | |
return internalCounter(val) |
NewerOlder