code stringlengths 10 1.34M | language stringclasses 1
value |
|---|---|
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// http://code.google.com/p/goprotobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// m... | Go |
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2012 The Go Authors. All rights reserved.
// http://code.google.com/p/goprotobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// m... | Go |
package main
import "fmt"
const(
fizz = 3
bizz = 5
count = 100
)
func main(){
var p bool
for i:=1; i<=count;i++{
p = false
if i% fizz == 0{
fmt.Print("Fizz")
p = true
}
if i % bizz == 0{
fmt.Print("Buzz")
p = true
}
if !p {
fmt.Printf("%v", i)
}
fmt... | Go |
package main
import (
"fmt"
"time"
)
const (
count int = 10
)
func main() {
t0()
t1()
}
func t0() {
t := time.Now().Nanosecond()
fmt.Println(time.Now().Nanosecond() - t)
i := 0
I:
fmt.Printf("%d,", i)
i++
if i < count {
goto I
}
fmt.Println(time.Now().Nanosecond() - t)
}
... | Go |
// client
package main
import (
"fmt"
"net"
"time"
)
const RECV_BUF_LEN = 1024
func main() {
//fmt.Println("Hello eoe!")
conn, err := net.Dial("tcp", "127.0.0.1:6666")
if err != nil {
panic(err.Error())
}
defer conn.Close()
buf := make([]byte, RECV_BUF_LEN)
for i := 0; i < 5; i++ {
//准备要发送的字符串
msg ... | Go |
// server
package main
import (
"fmt"
"io"
"net"
//"reflect"
)
const RECV_BUF_LEN = 1024
func main() {
//fmt.Println("Hello eoe!")
listener, err := net.Listen("tcp", "0.0.0.0:6666")
if err != nil {
panic("error listening:" + err.Error())
}
fmt.Println("Starting the server")
for {
conn, err := listene... | Go |
//http://www.cnblogs.com/vimsk/archive/2012/11/07/2759375.html
package main
import (
"github.com/lxn/go-winapi"
"strconv"
"syscall"
)
func _TEXT(_str string) *uint16 {
return syscall.StringToUTF16Ptr(_str)
}
func _toString(_n int32) string {
return strconv.Itoa(int(_n))
}
func main() {
var h... | Go |
//http://www.cnblogs.com/vimsk/archive/2012/11/13/2768784.html
package main
import (
. "github.com/lxn/go-winapi"
"os"
"syscall"
"unsafe"
)
var (
originWndProc HWND
)
const (
winWidth int32 = 500
winHeight int32 = 300
)
func _TEXT(str string) *uint16 {
a := syscall.StringToUTF16Ptr(str)... | Go |
/*http://studygolang.com/topics/78*/
package main
import (
"syscall"
)
func abort(funcname string, err error) {
panic(funcname + " failed: " + err.Error())
}
func print_version(v uint32) {
major := byte(v)
minor := uint8(v >> 8)
build := uint16(v >> 16)
print("windows version ", major, ".", mi... | Go |
///http://golang.usr.cc/thread-52855-1-1.html
package main
import (
"github.com/lxn/walk"
"github.com/lxn/walk/declarative"
"strings"
)
func main() {
var inTE, outTE *walk.TextEdit
MainWindow{
Title: "SCREAMO",
MinSize: Size{600, 400},
Layout: VBox{},
Children: []Widget{
Splitte... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"strings"
)
import "github.com/lxn/walk"
type EnvItem struct {
varName string
value string
}
ty... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"log"
)
import (
"github.com/lxn/go-winapi"
"github.com/lxn/walk"
)
const myWidgetWindowClass = "MyWidget Class"
... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"log"
"time"
)
import (
"github.com/lxn/polyglot"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
t... | Go |
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var le *walk.LineEdit
var wv *walk.WebView
... | Go |
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"path"
"strings"
)
import (
"github.com/lxn/walk"
)
type MainWindow struct {
*walk.MainWindow
tabWidget *wal... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"time"
)
import "github.com/lxn/walk"
type MyDialog struct {
*walk.Dialog
ui myDialogUI
}
func RunMyDial... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"log"
)
func main() {
if _, err := runMainWindow(); err != nil {
log.Fatal(err)
}
}
| Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"time"
)
type Foo struct {
FilePath string
Bar *Bar
Number float64
Date time.Time
Memo string
}
... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/lxn/walk"
)
var barModel *BarListModel = NewPopulatedBarListModel()
type BarListModel struct {
walk.ListMo... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
)
import (
"github.com/lxn/walk"
)
type MainWindow struct {
*walk.MainWindow
ui mainWindowUI
}
func run... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/lxn/walk"
)
type FooDialog struct {
*walk.Dialog
ui fooDialogUI
}
func runFooDialog(owner walk.RootWidg... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"errors"
"syscall"
"unsafe"
)
import (
. "github.com/lxn/go-winapi"
"github.com/lxn/walk"
)
type LogView struct {
walk.Widge... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"log"
"time"
)
import "github.com/lxn/walk"
func main() {
walk.SetPanicOnError(true)
myWindow, _ := walk.NewMain... | Go |
// Copyright 2012 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
"image"
"image/color"
"image/draw"
)
func main() {
var ... | Go |
// Copyright 2011 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/lxn/walk"
)
func main() {
// Specify that we want errors to be panics.
walk.SetPanicOnError(true)
// We... | Go |
// Copyright 2011 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"math/rand"
"sort"
"strings"
"time"
)
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
ty... | Go |
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"github.com/lxn/walk"
)
type MainWindow struct {
*walk.MainWindow
paintWidget *walk.CustomWidget
}
func createBitma... | Go |
// Copyright 2011 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"log"
"os"
"path/filepath"
"time"
)
import (
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
type... | Go |
package main
import (
"fmt"
"strconv"
)
func main() {
str := strconv.Itoa(1)
fmt.Println(str)
}
| Go |
package main
import (
"fmt"
)
type HelloPerson struct {
IHello
}
func (*HelloPerson) hi(str string) error {
fmt.Println("HelloPerson.hi--->", str)
return nil
}
| Go |
package main
/*import (
"fmt"
)*/
type IHello interface {
hi(str string) error
}
func main() {
iHelloes := map[string]IHello{}
iHelloes["pig"] = new(HelloPig)
iHelloes["person"] = new(HelloPerson)
_ = iHelloes["person"].hi("ss")
_ = iHelloes["pig"].hi("ss")
}
| Go |
package main
import (
"fmt"
)
type HelloPig struct {
IHello
}
func (*HelloPig) hi(str string) error {
fmt.Println("HelloPig.hi--->", str)
return nil
}
| Go |
//http://blog.csdn.net/xushiweizh/article/details/7034346
package main
import "fmt"
type IReadWirter interface {
Read(buf *byte, cb int) int
Write(buf *byte, cb int) int
}
type A struct {
a int
}
func NewA(param int) *A {
return &A{a: param}
}
func (this *A) Read(buf *byte, cb int) int {
re... | Go |
//http://blog.csdn.net/xushiweizh/article/details/7034346
package main
import "fmt"
type IReadWirter interface {
Read(buf *byte, cb int) int
Write(buf *byte, cb int) int
}
type A struct {
a int
}
func NewA(param int) *A {
return &A{a: param}
}
func (this *A) Read(buf *byte, cb int) int {
return cb
}
func (th... | Go |
package main
import (
"fmt"
"strings"
)
func main() {
/**byte转字符串*/
char := []byte{'a', 'b', 'c'}
char2str := string(char)
fmt.Println(char2str)
/**字符串转byte*/
str2char := []byte(char2str)
fmt.Println(str2char)
/**字符串长度,数组长度*/
charlen, strlen := len(str2char), len(str2char)
fmt.Println... | Go |
//http://www.oschina.net/code/snippet_173630_12202
package main
import (
"fmt"
"time"
)
func testTimer1() {
go func() {
fmt.Println("test timer1")
}()
}
func testTimer2() {
go func() {
fmt.Println("test timer2")
}()
}
func timer1() {
timer1 := time.NewTicker(1 * time.Second)
for ... | Go |
//http://www.dotcoo.com/golang-sync-mutex
package main
import (
"fmt"
"sync"
"time"
)
var lock *sync.Mutex
func main() {
lock = new(sync.Mutex)
go t1(2)
t1(3)
fmt.Printf("%s\n", "exit!")
}
func t1(i int) {
fmt.Println(i, "--->lock start")
lock.Lock()
fmt.Println(i, "--->lock")
time.Sleep(time.Second * 10... | Go |
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
wg := sync.WaitGroup{}
for i := 0; i < 3; i++ {
wg.Add(1)
go func(x, n int) {
for y := 0; y < n; y++ {
fmt.Printf("[%d]: %d\n", x, y)
}
wg.Done()
}(i, rand.Intn(5))
}
wg.Wait()
}
| Go |
package main
import (
"fmt"
"time"
)
type Test struct {
waitGroup *WaitGroupWrapper
Name string
}
func NewTest(name string, w *WaitGroupWrapper) *Test {
test := &Test{Name: name, waitGroup: w}
test.waitGroup.Wrap(func() { test.router() })
return test
}
func (t *Test) router() {
for {
fmt.Println("Tes... | Go |
package main
import (
"sync"
)
type WaitGroupWrapper struct {
sync.WaitGroup
}
func (w *WaitGroupWrapper) Wrap(cb func()) {
w.Add(1)
go func() {
cb()
w.Done()
}()
}
| Go |
package main
import (
"fmt"
"sync"
"time"
)
var lock *sync.Mutex
func main() {
lock = new(sync.Mutex)
go t1(2)
go t1(3)
fmt.Printf("%s\n", "exit!")
}
func t1(i int) {
println(i, "--->lock start")
lock.Lock()
println(i, "--->lock")
time.Sleep(time.Second * 10)
lock.Unlock()
println(i, "--->unlock")
}
| Go |
package main
import (
"fmt"
)
var a string
var sid = make(chan int, 1)
func f() {
fmt.Println(a)
sid <- 1
//print(a)
}
func hello() {
a = "hello, world"
go f()
}
func main() {
hello()
<-sid
}
| Go |
//http://kejibo.com/golang-slice-array-reflect/
package main
import (
"fmt"
"reflect"
)
func sliceType() {
vs := []interface{}{
[]int{1, 2, 3}, //slice 切片
[]int{1, 2, 3}, //切片再切还是切片
//[]int{1, 2, 3}[:],
[3]int{1, 2}, //array 数组,确定数组长度
[3]int{1, 2, 3}, //数组切一下,切出个 slice切片
//[3]int{... | Go |
package main
import (
"flag"
"fmt"
)
var (
showVersion = flag.Bool("version", false, "print version string")
httpAddress = flag.String("http-address", "0.0.0.0:4151", "<addr>:<port> to listen on for HTTP clients")
)
func main() {
fmt.Printf("%s\n", "hello, world")
printNumber()
// flag.Parse()
// fmt.Printl... | Go |
package main
import (
"fmt"
"reflect"
)
//http://blog.golang.org/2011/01/go-slices-usage-and-internals.html
func init0() {
/**数组不需要显式初始化;零值的数组是一个随时可用的数组,该数组的元素本身零*/
var a [4]int
fmt.Println(a)
a[0] = 1
i := a[0]
fmt.Println(i == 1)
fmt.Println(a[2] == 0)
}
func init1() {
b := [3]string... | Go |
package main
import (
"fmt"
"time"
)
func main() {
//时间戳
t := time.Now().Unix()
fmt.Println(t)
//时间戳int转Time实例
t1 := time.Unix(1368423922, 0000000000)
fmt.Println(t1)
//时间戳到具体显示的转化
fmt.Println(time.Unix(t, 0).String())
//带纳秒的时间戳
t = time.Now().UnixNano()
fmt.Println(t)
fmt.Print... | Go |
package main
import "fmt"
// import "time"
import "os"
import "os/signal"
import "syscall"
type signalHandler func(s os.Signal, arg interface{})
type signalSet struct {
m map[os.Signal]signalHandler
}
func signalSetNew() *signalSet {
ss := new(signalSet)
ss.m = make(map[os.Signal]signalHandler)
return ss
}
fu... | Go |
//http://outofmemory.cn/code-snippet/1172/Go-language-li-For-do-statement
package main
import (
"fmt"
)
const (
count int = 10
)
func main() {
for0()
for1()
for2()
for3()
}
func for0() {
sum := 0
for i := 0; i < count; i++ {
sum += i
}
fmt.Println(sum)
}
func for1() {
i, sum... | Go |
package main
import "fmt"
func main() {
var p *[10]int = new([10]int)
fmt.Println(&p)
testArray(p)
var p1 []int = make([]int, 10)
fmt.Println(&p1)
testArray1(p1)
}
func testArray(p *[10]int){
fmt.Println(&p)
}
func testArray1(p1 []int){
fmt.Println(p1)
}
| Go |
package main
import "fmt"
import "os"
import "os/signal"
import "syscall"
import "time"
import "math/rand"
// 该 chan 代表 线程 A 放入数据时, 只有当线程B取走数据时, 线程A才继续执行
var count = make(chan int)
// 同上
//var count = make(chan int, 0)
// 该 chan 只能存放一个数据, 当该 chan 中 已经存放一个数据时,其他的存放数据的线程,将被阻塞.
//var count = make(chan int, 1)
func mai... | Go |
package main
import (
"fmt"
"log"
"runtime"
"time"
)
func Sum(values []int, results chan chan int) {
result := make(chan int, 1)
results <- result
fmt.Println(values)
time.Sleep(time.Second * 5)
sum := 0
for _, value := range values {
sum += value
}
result <- sum
}
func main() {
... | Go |
//http://www.cnblogs.com/getong/archive/2013/03/19/2970045.html
package main
import (
"fmt"
"log"
"os"
"os/signal"
"runtime"
"syscall"
"time"
)
func main() {
fmt.Println(runtime.NumCPU())
runtime.GOMAXPROCS(runtime.NumCPU())
done := make(chan bool)
receive_channel := make(chan chan bool)
finish := make(c... | Go |
package main
import "fmt"
import "os"
import "os/signal"
import "syscall"
func main() {
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
fmt.Println("xylon-signal-1:")
fmt.Println("xylon-signal-2:", sig)
done <- tru... | Go |
package main
import "fmt"
type S struct {
a, b int
}
// String 实现了接口 fmt.Stringer
func (s *S) String() string {
return fmt.Sprintf("%s", s) // 调用 Sprintf 时会默认调用 s.String()
}
func main() {
s := &S{a: 1, b: 2}
fmt.Println(s)
}
| Go |
/**
sources:http://blog.163.com/huv520@126/blog/static/2776523920100313211221/
notes:
1.iota关键字用在const常量中;
2.未指定常量值情况,选取最近的表达式
3.iota作用域未括号或者const关键字范围
*/
package main
import "fmt"
const (
a1 = 1 << iota // 1 << 0
a2 // 1 << 1
a3 = iota // 2
)
const (
b1 = 1 << iota // a == 1 (iota has been r... | Go |
//http://blog.5d13.cn/resources/goweb/07.3.html
//http://bbs.studygolang.com/thread-11-1-1.html
package main
import (
"fmt"
"regexp"
)
func main() {
str := "ABB"
re, _ := regexp.Compile(`^[A-Z]{1,}$`)
macth := re.Find([]byte(str))
fmt.Println(string(macth))
}
| Go |
package main
import "fmt"
func main() {
// 简单声明
var sum int
sum = 100
// 声明并初始化
//var num int = 100
var a, b *int
a = &sum
b = a
//声明并初始化
var label string = "ss100"
//声明并初始化
name := "sfd"
//赋值操作
label = "2323242"
fmt.Println(a, b, label, name)
fmt.Println("Hello World!", ... | Go |
//https://gobyexample.com/random-numbers
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
/** 随机数 */
fmt.Print(rand.Intn(100), ",")
fmt.Print(rand.Intn(100))
fmt.Println()
fmt.Println(rand.Float64())
fmt.Print((rand.Float64()*5)+5, ",")
fmt.Print((rand.Float64() * 5) + 5)... | Go |
package main
import (
"flag"
"fmt"
"os"
)
var omitNewline = flag.Bool("n", false, "don't print final newline")
var c byte = 1
const (
Space = " "
Newline = "\n"
)
func main() {
flag.Parse()
var s string = ""
fmt.Print("参数个数:", flag.NArg(), "; values:")
for i := 0; i < flag.NArg(); i++... | Go |
package main
import (
"fmt"
"time"
)
func main() {
timer1 := time.NewTimer(time.Second * 1)
fmt.Println("start")
go func() {
//<-timer1.C
fmt.Println(time.Now())
fmt.Println(timer1.C)
}()
time.Sleep(10000)
}
| Go |
package main
import (
"fmt"
"runtime"
"sync/atomic"
"time"
)
func main() {
var ops uint64 = 0
for i := 0; i < 50; i++ {
go func() {
for {
atomic.AddUint64(&ops, 1)
runtime.Gosched()
}
}()
}
time.Sleep(time.Second)
opsFinal := atomic.LoadUint64(&ops)
fmt.Println("opsFinal:", opsFinal)
fm... | Go |
package main
import "fmt"
func main() {
var p *Point = new(Point)
p.setX(200)
p.setY(300)
fmt.Println(p.length())
fmt.Println(p.x, p.y)
p.length()
fmt.Printf("Hello, world; or Καλημέρα κόσμε; or こんにちは 世界\n")
}
| Go |
package main
import "math"
type Point struct {
x, y float64
}
func (self Point) length() float64 {
return math.Sqrt(self.x*self.x + self.y*self.y)
}
func (self *Point) Scale(factor float64) {
self.setX(self.x * factor)
self.setY(self.y * factor)
}
func (self *Point) setX(x float64) {
self.x ... | Go |
package main
import "math"
type Point struct {
x, y float64
}
func (self Point) length() float64 {
return math.Sqrt(self.x*self.x + self.y*self.y)
}
func (self *Point) Scale(factor float64) {
self.setX(self.x * factor)
self.setY(self.y * factor)
}
func (self *Point) setX(x float64) {
self.x ... | Go |
package mp
import (
"fmt"
"time"
)
type WAVPlayer struct {
stat int
progress int
signal chan int
}
func (wav *WAVPlayer) Play(source string) {
fmt.Println("Playing wav music", source)
wav.progress = 0
for wav.progress < 100 {
time.Sleep(100 * time.Millisecond) // 假装正在播放
fmt.Pr... | Go |
package mp
import "fmt"
type Player interface {
Play(source string)
}
func Play(source string, mtype string) {
var p Player
switch mtype {
case "MP3":
p = &MP3Player{}
case "WAV":
p = &WAVPlayer{}
default:
fmt.Println("Unsupported music type", mtype)
return
}
p.Play(source)
}
| Go |
package mp
import (
"fmt"
"time"
)
type MP3Player struct {
stat int
progress int
}
func (mp3 *MP3Player) Play(source string) {
fmt.Println("Playing MP3 music", source)
mp3.progress = 0
for mp3.progress < 100 {
time.Sleep(100 * time.Millisecond) // 假装正在播放
fmt.Print(".")
mp3.prog... | Go |
package library
type MusicEntry struct {
Id string
Name string
Artist string
Source string
Type string
}
| Go |
package library
import "errors"
type MusicManager struct {
musics []MusicEntry
}
func NewMusicManager() *MusicManager {
return &MusicManager{make([]MusicEntry, 0)}
}
func (m *MusicManager) Len() int {
return len(m.musics)
}
func (m *MusicManager) Get(index int) (music *MusicEntry, err error) {
if index < 0 || ... | Go |
package xylon
func Sum(a, b int) (int, error) {
return a + b, nil
}
| Go |
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"com/library"
"com/mp"
)
var lib *library.MusicManager
var id int = 1
var ctrl, signal chan int
func handleLibCommands(tokens []string) {
switch tokens[1] {
case "list":
for i := 0; i < lib.Len(); i++ {
e, _ := lib.Get(i)
fmt.Println(i+1,... | Go |
package main
import "com/xylon"
import "fmt"
func main() {
a, e := xylon.Sum(1, 2)
fmt.Println(a, e)
}
| Go |
package main
//https://github.com/localvar/makeepub
import (
"bufio"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
"strings"
)
type IniFile struct {
data map[string]string
}
func Open(path string) (*IniFile, error) {
f, e := os.Open(path)
if e != nil {
return nil, e
}
defer f.Close()
br := bufio.NewReader... | Go |
package main
import (
"bufio"
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
"time"
)
var (
reHeader = regexp.MustCompile("^[ \t]*<[hH]([1-6])[^>]*>([^<]*)</[hH]([1-6])>[ \t]*$")
reBody = regexp.MustCompile("^[ \t]*<(?i)body(?-i)[^>]*>$")
)
func setCoverPage(book *Epub, root str... | Go |
package main
import (
"archive/zip"
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
const (
mimetype = "mimetype"
toc_ncx = "toc.ncx"
content_opf = "content.opf"
meta_inf = "META-INF/container.xml"
)
var (
MediaType = map[string]string{
"": "application/octet-stream",
".html": ... | Go |
package main
//https://github.com/localvar/makeepub
import (
"bufio"
"io"
"os"
"strconv"
"strings"
)
type IniFile struct {
data map[string]string
}
func Open(path string) (*IniFile, error) {
f, e := os.Open(path)
if e != nil {
return nil, e
}
defer f.Close()
br := bufio.NewReader(f)
section := ""
m :... | Go |
// makeepub project doc.go
/*
makeepub document
*/
package main
| Go |
package main
import (
"fmt"
"github.com/syndtr/goleveldb/leveldb"
"strconv"
"time"
)
func main() {
db, err := leveldb.OpenFile("/usr/local/leveldbdata", nil)
if nil != err {
fmt.Println(err)
}
for i := 0; i < 10; i++ {
nano := time.Now().Nanosecond()
db.Put([]byte("ceshi"+strconv.Itoa(nano)), []byte("... | Go |
package main
/**
*http://sdutlinux.org/t/1058
*https://github.com/golang/groupcache/blob/master/lru/lru_test.go
*/
import (
"container/list"
)
type Key interface{}
type Cache struct {
MaxEntries int
ll *list.List
cache map[interface{}]*list.Element
}
type entry struct {
key Key
value interface{}
}
fu... | Go |
package main
import (
"fmt"
)
func main() {
cache := New(0)
ov, ok := cache.Add("123", "345")
fmt.Println(ov, ok)
ov, ok = cache.Add("123", "456")
fmt.Println(ov, ok)
fmt.Println(cache.ll.Len())
}
| Go |
// Copyright 2011 The Snappy-Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package snappy implements the snappy block-based compression format.
// It aims for very high speeds and reasonable compression.
//
// The C++ snappy ... | Go |
// Copyright 2011 The Snappy-Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package snappy
import (
"encoding/binary"
"errors"
)
// ErrCorrupt reports that the input is invalid.
var ErrCorrupt = errors.New("snappy: corrupt in... | Go |
// Copyright 2011 The Snappy-Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package snappy
import (
"encoding/binary"
)
// We limit how far copy back-references can go, the same as the C++ code.
const maxOffset = 1 << 15
// e... | Go |
package main
import (
"fmt"
)
type BigStruct struct {
C01 uint64
}
func Invoke1(a *BigStruct) uint64 {
a.C01++
return a.C01
}
func Invoke2(a BigStruct) uint64 {
a.C01++
return a.C01
}
func (a *BigStruct) Invoke3() uint64 {
a.C01++
return a.C01
}
func (a BigStruct) Invoke4() uint64 {
a.C01++
return a.C01... | Go |
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"
"github.lab/syndtr/goleveldb/leveldb/storage"
)
var (
filename string
child bool
)
func init() {
flag.StringVar(&filename, "filename", filepath.Join(os.TempDir(), "goleveldb_filelock_test"), "Filename used for testing")
... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package leveldb
import (
"time"
"github.lab/syndtr/goleveldb/leveldb/memdb"
"github.lab/syndtr/goleveldb/leveldb/opt"
)
... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package leveldb
import (
"errors"
"io"
"os"
"sync"
"sync/atomic"
"github.lab/syndtr/goleveldb/leveldb/iterator"
"git... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package leveldb
import (
"sort"
"sync/atomic"
"github.lab/syndtr/goleveldb/leveldb/cache"
"github.lab/syndtr/goleveldb/... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package iterator
import (
"github.lab/syndtr/goleveldb/leveldb/util"
)
// IteratorIndexer is the interface that wraps Comm... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package iterator provides interface and implementation to traverse over
// contents of a database.
package iterator
impor... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package iterator
import (
"errors"
"github.lab/syndtr/goleveldb/leveldb/comparer"
"github.lab/syndtr/goleveldb/leveldb/u... | Go |
// Copyright 2011 The LevelDB-Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Taken from: https://code.google.com/p/leveldb-go/source/browse/leveldb/record/record.go?r=1d5ccbe03246da926391ee12d1c6caae054ff4b0
// License, author... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package leveldb
import (
"errors"
"sync/atomic"
"unsafe"
"github.lab/syndtr/goleveldb/leveldb/iterator"
"github.lab/sy... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package leveldb
import (
"fmt"
"sort"
"github.lab/syndtr/goleveldb/leveldb/storage"
)
func shorten(str string) string {... | Go |
// Copyright (c) 2013, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package storage
import (
"bytes"
"os"
"sync"
"github.lab/syndtr/goleveldb/leveldb/util"
)
const typeShift = 3
type me... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reservefs.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package storage
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"ti... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package storage provides storage abstraction for LevelDB.
package storage
import (
"errors"
"io"
"github.lab/syndtr/g... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package storage
import (
"os"
"path/filepath"
)
type plan9FileLock struct {
f *os.File
}
func (fl *plan9FileLock) relea... | Go |
// Copyright (c) 2013, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package storage
import (
"syscall"
"unsafe"
)
var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
procMoveFileExW =... | Go |
// Copyright (c) 2012, Suryandaru Triandana <syndtr@gmail.com>
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// +build darwin freebsd linux netbsd openbsd
package storage
import (
"os"
"syscall"
)
type unixFileLock struct {
f *o... | Go |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.