Skip to content

Instantly share code, notes, and snippets.

View dxavx's full-sized avatar
🏠
Working from home

dxavx dxavx

🏠
Working from home
View GitHub Profile
@dxavx
dxavx / select_2.go
Created January 12, 2020 20:47
reading from a specific channel
package main
import (
"fmt"
)
func main() {
ch1 := make(chan int, 3)
ch1 <- 1
ch1 <- 2
@dxavx
dxavx / chain_2.go
Created January 12, 2020 19:47
write and read to channel
package main
import (
"fmt"
)
func main() {
in := make(chan int)
// In this subroutine, we open a channel and sequentially write the values 1...4
@dxavx
dxavx / chain_1.go
Last active January 12, 2020 19:18
not buffered channel
package main
import "fmt"
func main() {
ch1 := make(chan int, 1) // creating a channel specifying a type that is not buffered (mkfifo)
go func(in chan int) {
val := <-in // reading from a channel
fmt.Println("GO: get from chan", val)
@dxavx
dxavx / main.go
Created January 11, 2020 23:42
Prometheus metrics
package main
import (
"flag"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"math/rand"
"net/http"
"time"
@dxavx
dxavx / json.go
Last active January 11, 2020 23:36
JSON and struct
package main
import (
"encoding/json"
"fmt"
)
type User1 struct {
ID int `json:"user_id,int"` // tags
Username string
@dxavx
dxavx / main.go
Created January 11, 2020 23:10
Exec bash script
package main
import (
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("bash", "./job.sh")
@dxavx
dxavx / main.go
Last active January 11, 2020 19:25
does the file exist
package main
import (
"fmt"
"os"
)
func main() {
var ff = "/Users/IMG_01.jpg"
fmt.Println(FileExists(ff))
@dxavx
dxavx / main.go
Created January 11, 2020 19:03
simple Get request
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
@dxavx
dxavx / main.go
Created January 11, 2020 17:29
Checking the file for MIME type with subsequent loading
package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
@dxavx
dxavx / main.go
Created January 11, 2020 15:30
Listing directory
package main
import (
"fmt"
"io/ioutil"
"log"
"os/user"
)
func main() {