Skip to content

Instantly share code, notes, and snippets.

@Harsimran1
Harsimran1 / commented.Dockerfile
Last active December 29, 2021 21:45
Commented Dockerfile
FROM golang:1.16-alpine
WORKDIR /app
RUN apk add --no-cache ca-certificates git openssl
RUN go env -w GOPRIVATE=github.com/org-name/levven-go
RUN go env -w GO111MODULE=""
ARG GITHUB_TOKEN
@Harsimran1
Harsimran1 / Dockerfile
Last active December 29, 2021 21:45
Dockerfile to build a golang binary.
FROM golang:1.16-alpine
WORKDIR /app
RUN apk add --no-cache ca-certificates git openssl
RUN go env -w GOPRIVATE=github.com/org-name/levven-go
RUN go env -w GO111MODULE=""
ARG GITHUB_TOKEN
@Harsimran1
Harsimran1 / logrotate.yaml
Last active November 13, 2021 21:35
Create log file and enable log rotation using Ansible
---
- name: "Create or ensure log dir"
file:
path: "/var/log"
state: directory
recurse: yes
mode: "0755"
owner: "my_service_user"
group: "my_service"
package main
import (
"errors"
"net/http"
"time"
)
// makeRequest makes simple http request and returns an error channel
func makeRequest() <-chan error {
@Harsimran1
Harsimran1 / request.go
Last active March 8, 2021 17:32
Simple http GET request
package client
import (
"net/http"
)
// makeRequest makes simple http request and returns a response string
func makeRequest() error {
resp, err := http.Get("https://medium.com")
if err != nil {
package sendgrid
// Remove the interface and change the concrete type to public
type SendGrid struct {
/* impl */
}
// Change the NewSendGrid to return pointer to SendGrid instead.
func NewSendGrid(host string) *SendGrid {
@Harsimran1
Harsimran1 / sendgrid_with_interface.go
Created February 21, 2021 12:31
Sendgrid with interface
package sendgrid
type SendGrid interface {
SendValidationEmail(email string) error
SendPasswordChangeEmail(email string) error
}
// sendgrid is our Sendgrid implementation.
type sendgrid struct {
/* impl */
@Harsimran1
Harsimran1 / interface.go
Last active March 7, 2021 12:01
Golang Interface Definition Example
type Vehicle interface {
Drive()
}
// Car implements the Vehicle interface simply by implementing method Drive.
type Car struct{}
func (c Car) Drive() {
fmt.Println("Drive")
}
@Harsimran1
Harsimran1 / interface.java
Created December 3, 2020 02:12
Java Interface Definition Example
interface Vehicle
{
// public and abstract
void drive();
}
// A class that implements the interface.
class Car implements Vehicle
{
// Implementing the capabilities of
@Harsimran1
Harsimran1 / nginx.conf
Last active November 5, 2020 12:04
Nginx conf with ssl termination.
server {
listen 80;
server_name _;
# Redirect all traffic to SSL
return 301 https://$host$request_uri;
}
server {