September 7, 2020
tags Go Programming Software Engineering Requirements # Sorted array of lenght N Performance # Say an array contains N (search space o N) elements, and we divide N/2, getting a search space of N/2, how many steps do we need until we get down to just one an array of 1 element. O(log2 n) problem. Implementation # Can be implemented recursively or non-recursively.
...
September 3, 2020
tags Programming Go Programming Keywords # Cancellation: is when you are requesting some services, and you cancel this request Propagation: means that if we asked someone for a service then you tell that person to cancel
June 22, 2020
tags Go Programming Programming Code snippets The following implements a DataModel, like Django’s Model class which requires Validate and Save methods be implemented by whoever uses that Interface. The problem is the Model. m object will be nil, because Model cannot access the User due to the embedded Model struct within the User struct.
package main import "fmt" type DataModel interface { Validate() Save() } type Model struct { DataModel } func (m *Model) Validate(){ fmt.
...
June 21, 2020
tags Go Programming Programming Code snippets The following code reads a specific struct Tag by name.
import ( "reflect" "strings" "fmt" ) type Profile struct { Id int `validate:"numeric" json:"id"` First string `validate:"required" json:"first"` Last string `validate:"required" json:"last"` Birth string `validate:"required" json:"birth"` Sex string `validate:"required" json:"sex"` MaritalStatus string `validate:"required" json:"marital_status"` Children int `validate:"numeric" json:"children"` } func GetStructFieldValidators(data interface{}) map[string][]string { v := reflect.ValueOf(data) t := reflect.TypeOf(data) validators := make(map[string][]string) for i := 0; i < v.
...
June 19, 2020
tags Go Programming Programming import "fmt" func trace(name string) string { fmt.Println("Entering ", name) return name } func un(name string) string { fmt.Println("Exiting", name) return name } func a() { defer un(trace("a")) fmt.Println("Hello, world") } func b(){ defer un(trace("b")) fmt.Println("Before i < 10 loop") for i:=0 ; i < 10; i++{ defer fmt.Println("i =", i) } fmt.Println("After i < 10 loop") } func main(){ a() b() } Entering a Hello, world Exiting a Entering b Before i < 10 loop After i < 10 loop i = 9 i = 8 i = 7 i = 6 i = 5 i = 4 i = 3 i = 2 i = 1 i = 0 Exiting b
May 31, 2020
tags Programming Computer Science Related notes: Interesting Golang libraries
Packages # In Go, programs start running in package main. Package names are defined by the last element of the import path: import math/rand has files which begin with the package rand. Packages consists of a bunch of .go files.
Package identifiers (functions, variables, struct and other data), may be used in other packages, with a few exceptions. Go allows only exported identifiers to be called after the package import.
...
May 30, 2020
https://github.com/jmoiron/sqlx https://pg.uptrace.dev/guide/ https://github.com/go-pg/pg Entered on [2020-05-27 Wed 21:36]
<~/workspace/commit-validator/requirements.txt>
tags Go Programming Programming For an operand x of type T, the address operation &x generates a pointer of type *T to x. The operand must be addressable, that is, either a variable, pointer indirection, or slice indexing operation; or a field selector of an addressable struct operand; or an array indexing operation of an addressable array. As an exception to the addressability requirement, x may also be a (possibly parenthesized) composite literal.
...