Skip to content

Instantly share code, notes, and snippets.

package main
import (
"database/sql"
"fmt"
// without the underscore _, you will get imported but not
// used error message
_ "github.com/go-sql-driver/mysql"
"os"
@pm-kartik-sura
pm-kartik-sura / gist:5ebbd1f826eb0892d3db
Created June 11, 2015 08:15
write string to a file
package main
import (
"fmt"
"io"
"os"
)
func main() {
@pm-kartik-sura
pm-kartik-sura / gist:48cf34f02e377c29304e
Created June 11, 2015 08:08
read input from console
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
consolereader := bufio.NewReader(os.Stdin)
package main
import (
"fmt"
"io/ioutil"
)
func main() {
file, err := ioutil.ReadFile("testfile.txt")
// HTTPRequester project main.go
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
)
@pm-kartik-sura
pm-kartik-sura / pause.go
Created May 25, 2015 10:18
adding pause in go
package main
import ( "fmt"
"time"
)
func main() {
fmt.Println("Hello world!")
duration := time.Second
time.Sleep(duration)
}
import "encoding/json"
//Encode
byt, _ := json.Marshal(true)
fmt.Println(string(byt))
//Decode
if err := json.Unmarshal(byt, &dat); err != nil {
panic(err)
}
@pm-kartik-sura
pm-kartik-sura / redigo
Created May 19, 2015 09:19
Redigo pools
package main
import "fmt"
import "github.com/garyburd/redigo/redis"
func newPool() *redis.Pool {
return &redis.Pool{
MaxIdle: 80,
MaxActive: 12000, // max number of connections
Dial: func() (redis.Conn, error) {