Skip to content

Instantly share code, notes, and snippets.

View dhanielsales's full-sized avatar
✌️

Dhaniel Sales dhanielsales

✌️
View GitHub Profile
@dhanielsales
dhanielsales / hotel.go
Created April 12, 2024 20:00
Context and Timeout operations
// path: hotel/hotel.go
package hotel
import (
"context"
"errors"
"time"
)
type Reserve struct {
@dhanielsales
dhanielsales / main.go
Created April 11, 2024 11:48
Mutex and Locks
// path: main.go
package main
import (
"fmt"
"golang-tests/wallet"
"sync"
)
type Payment struct {
@dhanielsales
dhanielsales / env.go
Created April 10, 2024 13:12
Singleton Design Pattern Golang
// path: env/env.go
package env
import (
"log"
"os"
"reflect"
"strconv"
"sync"
)
@dhanielsales
dhanielsales / field.go
Created April 4, 2024 20:16
Functional Options Pattern Golang
// path: user/field.go
package user
type Field struct {
firstName string
lastName string
email string
nationality string
birthDate int64
occupation string
@dhanielsales
dhanielsales / main.go
Created April 2, 2024 15:11
JSON Validator
// path: main.go
package main
import (
"fmt"
"github.com/go-playground/validator/v10"
"golang-tests/json_validator"
)
@dhanielsales
dhanielsales / api.go
Created April 1, 2024 15:50
Adapter pattern
// path: api/api.go
package api
import (
"encoding/json"
"log/slog"
"net/http"
)
type HttpContext struct {
@dhanielsales
dhanielsales / main.go
Last active February 16, 2024 14:11
main.go
package main
import (
"encoding/json"
"fmt"
"strconv"
"sync"
ffmpeg "github.com/u2takey/ffmpeg-go"
)
@dhanielsales
dhanielsales / component.ts
Last active April 4, 2021 19:38
component.ts
import React from 'react';
import { useButtons } from '~/contexts/ButtonsContext';
import { Creators } from '~/contexts/ButtonsContext/ducks';
const { setValue, increment, decrement } = Creators;
const Test: React.FC = () => {
const { state, dispatch } = useButtons();
@dhanielsales
dhanielsales / ducks.ts
Last active April 4, 2021 19:10
ducks.ts
import { Action, createActions, createReducer } from 'context-spices';
import { State } from './index';
export enum TypesNames {
INCREMENT = 'INCREMENT',
DECREMENT = 'DECREMENT',
SET_VALUE = 'SET_VALUE',
}
export type Increment = Action<TypesNames.INCREMENT>;
@dhanielsales
dhanielsales / index.tsx
Last active April 3, 2021 13:08
ExampleContext
import React, {
createContext,
useContext,
useReducer
} from 'react';
import { Action } from 'context-spices';
const INITIAL_DATA = {
count: 0,
};