This file contains hidden or 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" | |
func main() { | |
ben := &Ben{name: "Ben"} | |
jerry := &Jerry{name: "Jerry"} | |
var maker IceCreamMaker = ben | |
var loop0, loop1 func() |
This file contains hidden or 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
// request https | |
// disable security checks globally for all requests of the default client | |
func main() { | |
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} | |
_, err := http.Get("https://golang.org/") | |
if err != nil { | |
fmt.Println(err) | |
} | |
} |
This file contains hidden or 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 ( | |
"sync" | |
"sync/atomic" | |
"testing" | |
) | |
type Config struct { | |
a []int |
This file contains hidden or 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
#include <stdio.h> | |
#include <unistd.h> | |
int main(void) { | |
pid_t fpid; // fpid 表示 fork 函数返回值 | |
int count=0; | |
// 调用 fork, 创建出子进程 | |
fpid = fork(); |
This file contains hidden or 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 ( | |
"sync" | |
"sync/atomic" | |
) | |
func main() { | |
type Map map[string]string | |
var m atomic.Value |
This file contains hidden or 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 | |
func main() { | |
// holds current server configuration 动态更新当前服务的配置 | |
var config atomic.Value | |
go func() { | |
// Reload config every 10 seconds 每 10 秒重载配置 | |
// and update config value with the new version 用新版本的值更新配置项 | |
for { |
This file contains hidden or 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 "time" | |
import "sync" | |
import "flag" | |
import "os" | |
import "log" | |
import "runtime" | |
import "runtime/pprof" | |
import "runtime/trace" |
This file contains hidden or 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
type InterfaceA interface { | |
A() | |
B() | |
C() | |
D() | |
} | |
type ImplA struct { | |
InterfaceA | |
} |
This file contains hidden or 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 ( | |
"context" | |
"fmt" | |
"time" | |
) | |
const shortDuration = time.Millisecond |
This file contains hidden or 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
#include <iostream> | |
// 函数声明 | |
void func(void); | |
static int count = 10; /* 全局变量 */ | |
int main() | |
{ | |
while(count--) |