This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These examples demonstrate more intricate uses of the flag package. | |
package main | |
import ( | |
"errors" | |
"flag" | |
"fmt" | |
"strings" | |
"time" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m.Conn.SetReadDeadline(time.Now().Add(delay)) | |
for { | |
n, err := m.Conn.Read(buffer) | |
if err != nil { | |
log.Println(err) | |
} | |
if n > 0 { | |
// something was read before the deadline | |
// let's delay the deadline | |
m.Conn.SetReadDeadline(time.Now().Add(delay)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required (VERSION 3.0) | |
project (lua_embed C) | |
find_package(Lua REQUIRED) | |
include_directories ( | |
${CMAKE_CURRENT_BINARY_DIR} | |
${CMAKE_CURRENT_SOURCE_DIR} | |
${LUA_INCLUDE_DIR} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function f(x, y) | |
return x + y | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import lua "github.com/yuin/gopher-lua" | |
func Double(L *lua.LState) int { | |
lv := L.ToInt(1) /* get argument */ | |
L.Push(lua.LNumber(lv * 2)) /* push result */ | |
return 1 /* number of results */ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
lua "github.com/yuin/gopher-lua" | |
) | |
func main() { | |
L := lua.NewState() | |
defer L.Close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
var ( | |
VERSION string | |
BUILD_TIME string | |
GO_VERSION string | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//step1:初始一个counter, with help string | |
pushCounter = prometheus.NewCounter(prometheus.CounterOpts{ | |
Name: "repository_pushes", | |
Help: "Number of pushes to external repository.", | |
}) | |
//setp2: 注册容器 | |
err = prometheus.Register(pushCounter) | |
if err != nil { | |
fmt.Println("Push counter couldn't be registered AGAIN, no counting will happen:", err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. 场景:只有一个接收通道。使用for range,如果channel关闭则会自动退出循环 | |
go func(in <-chan int) { | |
// Using for-range to exit goroutine | |
// range has the ability to detect the close/end of a channel | |
for x := range in { | |
fmt.Printf("Process %d\n", x) | |
} | |
}(inCh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io/ioutil" | |
"net/http" | |
"runtime" | |
"github.com/Jeffail/tunny" | |
) |
OlderNewer