{ "main": { "prefix": "fmain", "description": "main function", "body": ["package main\n", "func main() {", "\t$1", "}"] }, "basicmainfile": { "prefix": "basic", "description": "basic main file", "body": [ "package main\n", "import (", "\t\"log\"", "\t\"net/http\"", "\t\"os\"\n", "\t\"github.com/go-chi/chi\"", "\t\"github.com/go-chi/cors\"", "\t\"github.com/joho/godotenv\"", ")\n", "func main() {", "\tgodotenv.Load(\".env\")\n", "\tport := os.Getenv(\"PORT\")", "\tif port == \"\" {", "\t\tlog.Fatal(\"PORT environment variable is not set\")", "\t}\n", "\trouter := chi.NewRouter()\n", "\trouter.Use(cors.Handler(cors.Options{", "\t\tAllowedOrigins: []string{\"https://*\", \"http://*\"},", "\t\tAllowedMethods: []string{\"GET\", \"POST\", \"PUT\", \"DELETE\", \"OPTIONS\"},", "\t\tAllowedHeaders: []string{\"*\"},", "\t\tExposedHeaders: []string{\"Link\"},", "\t\tAllowCredentials: false,", "\t\tMaxAge: 300,", "\t}))\n", "\tv1Router := chi.NewRouter()", "\tv1Router.Get(\"/healthz\", handlerReadiness)", "\tv1Router.Get(\"/err\", handlerErr)\n", "\trouter.Mount(\"/v1\", v1Router)", "\tsrv := &http.Server{", "\t\tAddr: \":\" + port,", "\t\tHandler: router,", "\t}\n", "\tfileServer := http.FileServer(http.Dir(\"./static/\"))", "\tmux.Handle(\"/static/*\", http.StripPrefix(\"/static\", fileServer))\n", "\tlog.Printf(\"Serving on port: %s\\n\", port)", "\tlog.Fatal(srv.ListenAndServe())", "}" ] }, "error": { "prefix": "ife", "description": "if statment for error", "body": ["if err != nil {", "\t$1", "}"] }, "println": { "prefix": "pl", "description": "fmt.Println", "body": ["fmt.Println(\"$1\")"] }, "sprintf": { "prefix": "spf", "description": "fmt.Sprintf", "body": ["fmt.Sprintf(\"$1\")"] }, "handler": { "prefix": "hand", "description": "http.Handler", "body": ["func $1(w http.ResponseWriter, r *http.Request) {", "\t", "}"] }, "chirouter": { "prefix": "chi", "description": "import for chi router", "body": ["github.com/go-chi/chi/v5"] }, "godotenv": { "prefix": "godotenv", "description": "Go dot env", "body": ["\"github.com/joho/godotenv\""] }, "potgresdriver": { "prefix": "postgresdriver", "description": "Postgres Driver", "body": ["\"https://github.com/lib/pq\""] }, "import": { "prefix": "impt", "description": "import tag", "body": ["import (", "\t\"$1\"", ")\n"] }, "funcwithreceiver": { "prefix": "fr", "description": "Function with some receiver", "body": ["func ($1 *$2) $3 {", "\t", "}"] }, "sqlcontext": { "prefix": "ctx", "description": "context with timeout", "body": [ "ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)\n", "defer cancel()\n" ] }, "fecho": { "prefix": "fecho", "description": "echo with fasthttp", "body": [ "package main\n", "import (", "\t\"net/http\"", "\t\"github.com/labstack/echo/v4\"", ")\n", "func main() {", "\te := echo.New()\n", "\te.GET(\"/\", func(c echo.Context) error {", "\t\treturn c.String(http.StatusOK, \"Hello, World!\")", "\t})\n", "\te.Static(\"/static\", \"static\")", "\te.Logger.Fatal(e.Start(\":8000\"))", "}" ] } }