Skip to content

Instantly share code, notes, and snippets.

View marvinhosea's full-sized avatar
🎯
Pin point

Marvin Collins Hosea marvinhosea

🎯
Pin point
View GitHub Profile
@marvinhosea
marvinhosea / Example.go
Created February 20, 2023 15:09
Example
package main
import (
"errors"
"fmt"
"log"
)
var (
errOne = errors.New("error one")
@marvinhosea
marvinhosea / Child context.go
Last active February 20, 2023 20:19
Child context.go
package main
import (
"context"
"errors"
"log"
)
func main() {
parentCtx, parentCancelWithCause := context.WithCancelCause(context.Background())
@marvinhosea
marvinhosea / Contexpareet.go
Created February 20, 2023 10:35
Contexpareet.go
package main
import (
"context"
"errors"
"log"
)
func main() {
parentCtx, parentCancelWithCause := context.WithCancelCause(context.Background())
@marvinhosea
marvinhosea / cause.go
Last active February 20, 2023 20:06
Cause
package main
import (
"context"
"errors"
"log"
)
func main() {
@marvinhosea
marvinhosea / Bogus.go
Created February 19, 2023 13:27
Bogus
package main
import (
"errors"
"fmt"
"log"
)
func main() {
err := errors.New("first error")
@marvinhosea
marvinhosea / Main.go
Last active February 20, 2023 14:55
Main
package main
import (
"encoding/json"
"errors"
"log"
"regexp"
)
var (
@marvinhosea
marvinhosea / Main-main.go
Last active February 20, 2023 09:05
Main.go
func main() {
password := ""
response := make(map[string]any)
var passwordErrs []string
err := passwordValidator(password)
if err != nil {
// code validation goes here
}
@marvinhosea
marvinhosea / Main-password-validator.go
Last active February 20, 2023 08:59
Main-password-validator.go
func passwordValidator(password string) error {
var errs []error
// validates if password is empty
if password == "" {
errs = append(errs, ErrPasswordRequired)
}
// validates if password contains small(lowercase) letters
pattern1 := `[a-z]`
ok, err := regexp.MatchString(pattern1, password)
@marvinhosea
marvinhosea / main1.go
Created February 18, 2023 21:11
Main Initial
package main
import (
"errors"
"log"
"regexp"
)
var (
ErrPasswordRequired = errors.New("password is required")
@marvinhosea
marvinhosea / Response.json
Last active February 19, 2023 08:37
Login response
{
"password": [
"password is required",
"password must have a capital letter",
"password must have a number",
"password must have a special character"
]
}