Skip to content

Instantly share code, notes, and snippets.

View vedashree29296's full-sized avatar

Vedashree Patil vedashree29296

View GitHub Profile
@vedashree29296
vedashree29296 / goc-deployment.yml
Created September 17, 2021 10:48
GC: Manifest file for example Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
namespace: my-namespace
labels:
app: my-deployment
spec:
replicas: 2
selector:
@vedashree29296
vedashree29296 / my-pod.yml
Created August 13, 2021 03:46
Go Chronicles: Simple Manifest file to create a Pod with an env variable
apiVersion: v1
kind: Pod
metadata:
name: my-pod
namespace: my-namespace
spec:
containers:
- name: my-pod-container
image: go-chronicles-pod
imagePullPolicy: Never
@vedashree29296
vedashree29296 / my-pod.yml
Created August 13, 2021 03:45
Go Chronicles: Simple Manifest file to create a Kubernetes Pod
apiVersion: v1
kind: Pod
metadata:
name: my-pod
namespace: my-namespace
spec:
containers:
- name: my-pod-container
image: go-chronicles-pod
imagePullPolicy: Never
@vedashree29296
vedashree29296 / devtron-install.sh
Created June 16, 2021 04:52
Script to install devtron using kubectl
wget https://raw.githubusercontent.com/devtron-labs/devtron/main/manifests/install/devtron-operator-configs.yaml
kubectl create ns devtroncd
kubectl -n devtroncd apply -f https://raw.githubusercontent.com/devtron-labs/charts/main/charts/devtron/crds/crd-devtron.yaml
kubectl apply -n devtroncd -f https://raw.githubusercontent.com/devtron-labs/charts/main/charts/devtron/templates/install.yaml
kubectl apply -n devtroncd -f devtron-operator-configs.yaml
kubectl apply -n devtroncd -f https://raw.githubusercontent.com/devtron-labs/devtron/main/manifests/install/devtron-installer.yaml
package rest
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"
@vedashree29296
vedashree29296 / createcategory_test.go
Created April 21, 2021 05:23
Test to create a category for go chronicles
package rest
import (
"encoding/json"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"
@vedashree29296
vedashree29296 / uploadimage.go
Created April 14, 2021 04:59
Upload Handler for petstore Go chronicles
var imageDir string = "images"
func UploadPetImage(c echo.Context) error {
// Get id from Multipart form data
id, err := strconv.Atoi(c.FormValue("id"))
// get file form form data
file, err := c.FormFile("file")
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Couldn't read file from form value")
}
@vedashree29296
vedashree29296 / create-category-no-returns.go
Created February 9, 2021 06:23
Create a category with no return value
//CreateCategory : create a new Category in DB
func (c *Category) CreateCategory() error {
// prepare the query
stmt, err := client.DbClient.Prepare("INSERT INTO category (category_name) values ($1);")
if err != nil {
return err
}
//closing the statement to prevent memory leaks
defer stmt.Close()
@vedashree29296
vedashree29296 / create-category-with-id.go
Created February 9, 2021 06:19
Create a new category and return an id
//CreateCategory : create a new Category in DB
func (c *Category) CreateCategory() (int, error) {
//Create and execute the query
row := client.DbClient.QueryRow("INSERT INTO category (category_name) values ($1) RETURNING id;", c.CategoryName)
// save the data in an object
switch err := row.Scan(&c.ID); err {
// success, no errors
case nil:
return c.ID, nil
// In case of no output rows
@vedashree29296
vedashree29296 / getall-category.go
Created February 9, 2021 06:18
Get all categories
//GetAllCategory : Get all Categories from DB
func (c Category) GetAllCategory() ([]*models.Category, error) {
var categories []*models.Category // this will hold final result
//execute the query
rows, err := client.DbClient.Query("SELECT * from category")
defer rows.Close()
// iterate through rows
for rows.Next() {
// Bind to model
err = rows.Scan(&c.ID, &c.CategoryName)