for i, c := range s { char := strings.ToLower(string(c)) word := strings.Repeat(char, i+1) words[i] = strings.Title(word) } return strings.Join(words, "-") }
i, b := range []byte(s) { if i > 0 { bs = append(bs, '-') } u, l := b, b if b >= 'a' && b <= 'z' { u -= 32 } else { l += 32 } bs = append(bs, u) for j := 0; j < i; j ++ { bs = append(bs, l) } } return string(bs)
for _, name := range parts[0].path { if v.Type().Kind() == reflect.Ptr { if v.IsNil() { v.Set(reflect.New(v.Type().Elem())) } v = v.Elem() } v = v.FieldByName(name) } // Don't even bother for unexported fields. if !v.CanSet() { return nil } // Dereference if needed. t := v.Type() if t.Kind() == reflect.Ptr { t = t.Elem() if v.IsNil() { v.Set(reflect.New(t)) github.com/gorilla/schema
{ for i := 0; i < 5; i ++ { time.Sleep(time.Second) fmt.Println(s) } } func main() { go say("world") // create a new goroutine say("hello") // current goroutine time.Sleep(time.Second) }
time.Sleep(time.Second * 2) fmt.Println("Final Counter:", counter) } func incrementor(s string) { rand.Seed(time.Now().UnixNano()) for i := 0; i < 10; i ++ { x := counter x ++ time.Sleep(time.Duration(rand.Intn(3)) * time.Millisecond) counter = x fmt.Println(s, i, "Counter:", counter) } }
4 Foo: 5 Foo: 6 Foo: 7 Foo: 8 Bar: 0 Bar: 1 Bar: 2 Foo: 9 Foo: 10 Bar: 3 Foo: 11 Foo: 12 Bar: 4 Bar: 5 Foo: 13 Bar: 6 Bar: 7 Foo: 14 Bar: 8 Bar: 9 Bar: 10 Bar: 11 Bar: 12 Bar: 13 Foo: 15 Bar: 14 Bar: 15 Bar: 16 Bar: 17 Bar: 18 Bar: 19 Foo: 16 Foo: 17 Foo: 18 Foo: 19 Final Counter: 40
e = syscall.Open(name, flag|syscall.O_CLOEXEC, syscallMode(perm)) if e == nil { break } // On OS X, sigaction(2) doesn't guarantee that SA_RESTART will cause // open(2) to be restarted for regular files. This is easy to reproduce on // fuse file systems (see http: //golang.org/issue/11180). if runtime.GOOS == "darwin" && e == syscall.EINTR { continue } return nil, &PathError{"open", name, e} }
package os // According to sticky(8), neither open(2) nor mkdir(2) will create // a file with the sticky bit set. const supportsCreateWithStickyBit = false
cache the results if there is an error type cacheOnce struct { m sync.Mutex done uint32 } // Copied from sync.Once but we don't want // to cache the results if there is an error func (o *cacheOnce) cache(f func() error) { if atomic.LoadUint32(&o.done) == 1 { return } // ... github.com/kubernetes/kubernetes/pkg/volume/ metrics_cached.go
the given status code. Conventionally, // code zero indicates success, non-zero an error. // The program terminates immediately; deferred // functions are not run. func Exit(code int) { // ... } Документация к API
we were able to stop the timer, that means it // was running (hadn't yet started the fallback), but // we just got an error on the primary path, so start // the fallback immediately (in 0 nanoseconds). fallbackTimer.Reset(0) }