Skip to content

Instantly share code, notes, and snippets.

@YagmurOzden
YagmurOzden / TakeDataFromgithub.go
Created December 7, 2022 06:48
Takes data from github and returns the value as string
// Takes data from github and returns the value as string
func TakeDataFromgithub(URL string, FileName string) billy.File {
log.Printf(" Started to fetch data from Github")
fs := memfs.New()
//Authenticate and clone the repository
repo, err := git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
URL: URL,
})
@YagmurOzden
YagmurOzden / ParseDataByteToStr.go
Created December 1, 2022 06:09
For reading files that are bytes. GOLang
// For reading files that are bytes
func ParseData(file billy.File) string {
log.Printf("%v Started to parse file data to string", APINAME)
buf := make([]byte, 1)
var data string
for {
n, err := file.Read(buf)
if err == io.EOF {
break
}
@YagmurOzden
YagmurOzden / ReadFromGithub.go
Created December 1, 2022 06:05
Read Files From Github using GOLang
func main(){
jsonBody := TakeDataFromgithub("https://"+GetEnv("UserName")+":"+GetEnv("GithubToken")+GetEnv("Path"), GetEnv("FileName2"))
}
// Takes data from github and returns the value as string
func TakeDataFromgithub(URL string, FileName string) string {
log.Printf("%v Started to fetch data from Github", APINAME)
fs := memfs.New()
@YagmurOzden
YagmurOzden / API_controller.go
Created December 1, 2022 06:03
API controller using via fiber and GOLang
package controller
import (
model "Read-From-Github/model"
"bytes"
"encoding/json"
"io"
"log"
"os"
package model
type VMs struct {
Provider string `json:"provider,omitempty" ` //AWS , Azure:
ProjectID string `json:"projectId,omitempty"` //AWS: Account, Azure: Subscription
Location string `json:"location,omitempty"` //AWS: Region, Azure: Resporce Group
VMName string `json:"vmName,omitempty"` //Virtual Machine Name
VMStartAt string `json:"startsAt,omitempty"` //Virtual Machine start time
VMStopAt string `json:"stopsAt,omitempty"` //Virtual Machine stop time
Credential interface{} `json:"credential,omitempty"` //VirtualMachine's credential information
package routes
import (
controller "Github/controller"
"github.com/gofiber/fiber/v2"
)
func VMRoute(app *fiber.App) {
package main
import (
"Github/controller"
"Github/routes"
"log"
"github.com/gofiber/fiber/v2"
)
@YagmurOzden
YagmurOzden / json_marshal_unmarshal.go
Created November 24, 2022 09:00 — forked from miguelmota/json_marshal_unmarshal.go
Golang JSON Marshal (struct to string) (M for "Make json") and Unmarshal (string to struct) (U for "Unmake json") example
package main
import (
"encoding/json"
"fmt"
)
func main() {
type MyStruct struct {
Message string `json:"message"`
@YagmurOzden
YagmurOzden / validateVM.js
Last active July 30, 2023 07:56
Select virtual machine by its name (also, this action checks whether VM tools are installed, if VM is powered on, etc.)
// VMware vRealize Orchestrator action sample
// vRA 8.8.0
//input type : hostname [string]
//return type: VC:VirtualMachine
var vmSearch = VcPlugin.getAllVirtualMachines(null, hostname);
if (vmSearch.length > 1) {
for each (var vmObj in vmSearch) {
if (vmObj.summary.guest) {
System.log("Matched ## " + vmObj.summary.guest.hostName);
@YagmurOzden
YagmurOzden / getConfigurationElements.js
Created August 29, 2022 09:29
Returns the configuration element
// VMware vRealize Orchestrator action sample
// vRA 8.7.0
// input types: categoryPath [string]
configName [string]
// return type: ConfigurationElement
var category = Server.getConfigurationElementCategoryWithPath(categoryPath);
for each (var c in category.configurationElements){
if (c.name == configName){
return c;