Skip to content

Instantly share code, notes, and snippets.

View BNPrashanth's full-sized avatar

Prashanth BNPrashanth

  • Colombo, Sri Lanka
View GitHub Profile
package main
import (
"fmt"
c "./config"
"github.com/spf13/viper"
)
func main() {
package config
// Configurations exported
type Configurations struct {
Server ServerConfigurations
Database DatabaseConfigurations
EXAMPLE_PATH string
EXAMPLE_VAR string
}
server:
port: 8080
database:
dbname:
dbuser: "dbuser"
dbpassword: "dbpassword"
EXAMPLE_VAR: "variable from config.yml"
EXAMPLE_PATH: "path from config.yml"
package main
import (
s "gsheet-to-json-csv/src/services"
u "gsheet-to-json-csv/src/utils"
"os"
)
func main() {
// Strting the Application
package services
import (
"encoding/csv"
"encoding/json"
"errors"
u "gsheet-to-json-csv/src/utils"
"io/ioutil"
"net/http"
"os"
package utils
import (
"fmt"
"log"
"os"
"path/filepath"
)
// ErrorResponse exported
func WriteLanguageFiles(csvFilePath string) *u.ErrorResponse {
csvFile, err := os.Open(csvFilePath)
if err != nil {
u.ErrorLogger.Println("Cannot open file:"+csvFilePath, err)
return u.ReturnErrorResponse(err, "Cannot open file:"+csvFilePath)
}
csvFileContent, err := csv.NewReader(csvFile).ReadAll()
for i, lang := range csvFileContent[0][1:] {
func Download(url string, filename string, timeout int64) *u.ErrorResponse {
u.GeneralLogger.Println("Downloading", url, "...")
client := http.Client{
Timeout: time.Duration(timeout * int64(time.Second)),
}
resp, err := client.Get(url)
if err != nil {
u.ErrorLogger.Println("Cannot download file from the given url", err)
return u.ReturnErrorResponse(err, "Cannot download file from the given url")
}
package main
import (
u "go-logger/src/utils"
)
func main() {
// Strting the Application
u.GeneralLogger.Println("Starting..")
GeneralLogger = log.New(generalLog, "General Logger:\t", log.Ldate|log.Ltime|log.Lshortfile)
ErrorLogger = log.New(generalLog, "Error Logger:\t", log.Ldate|log.Ltime|log.Lshortfile)