Golang
var a int
Статически строго типизированный язык
var b []int
m := make(map[string][]int)
var (
a int
b []int
m = make(map[string][]int)
)
type MyOwnString string
func (str MyOwnString) Upcase() MyOwnString {
return MyOwnString(
strings.ToUpper(string(str))
)
}
func Handle(name Filename) {
...
}
type Uploader struct {
Path string
Payload []byte
}
type Post struct {
Title string `json:"title" xml:"Head" orm:"size(255)"`
Content []byte `json:"body" xml:"Body"`
Tags []*Tag `xml:"Tags>Tag" orm:"reverse(many)"`
}
type Handler func(*Request)
func (handle Handler) Serve(r *Request) {
handle(request)
}
package main
import (
"strings"
)
package main
import (
"strings"
"io/ioutil"
)
package main
import (
"strings"
"io/ioutil"
"github.com/valyala/gorpc"
)
НЕТ ВЕРСИЙ
Варианты
- Копирование всех зависимостей
- Внешние сервисы
- Страдать
- dep
type Server struct {
address string
config *Config
MaxRequestCount int
}
func (s *Server) Start() {
...
}
func (s *Server) stop() {
...
}
private
private
public
public
number := 1
&number // => 0xc208042058
number := 1
&number // => 0xc208042058
var pointer *int
pointer = &number
pointer // => 0xc208042058
*pointer // => 1
number := 1
&number // => 0xc208042058
var pointer *int
pointer = &number
pointer // => 0xc208042058
*pointer // => 1
*pointer = 2
number // => 2
func Request(data Data) {
data.Type = "Error"
}
func Request(data *Data) {
data.Type = "Error"
}
ARRAYS == POINTERS
Channels & Goroutines
go func(){
...
}()
func Serve() error {
...
}
go Serve()
func AllPosts() (chan *Post) {
channel := make(chan *Post)
go func(){
defer close(channel)
var posts []*Post
for i := 0; i < PostTable.Count(); i+=1000 {
PostTable.Limit(1000).Offset(i).All(&posts)
for _, post := range posts {
channel <- post
}
}
}()
return channel
}
for post := range AllPosts() {
...
}
select {
case signal := <-sChannel:
...
case <- timer:
...
}
Interfaces
type OAuth interface {
}
type OAuth interface {
Request(*Request) (*Response, eror)
Callback(*Request) (*Response, error)
}
10 проектов
ИТОГО
Сложная отладка
Производительность и потребление памяти
vast
api
api ........................... up (Mar17, 1%, 17Mb, <25743>)
sidekiq
sidekiq ....................... up (Mar17, 0%, 219Mb, <25751>)
web
unicorn ....................... up (Mar17, 0%, 116Mb, <25768>)
child-25820 ................. up (Mar17, 0%, 159Mb, <25820>)
child-25823 ................. up (Mar17, 0%, 162Mb, <25823>)
medialib
services
iframe ........................ up (00:24, 9%, 6Mb, <19437>)
transform ..................... up (00:24, 6%, 10Mb, <19408>)
uploader ...................... up (00:24, 0%, 9Mb, <19423>)
sidekiq
first ......................... up (16:13, 0%, 80Mb, <21492>)
second ........................ up (16:13, 0%, 72Mb, <21619>)
third ......................... up (16:13, 0%, 70Mb, <21501>)
web
puma .......................... up (16:13, 0%, 72Mb, <21536>)
child-21539 ................. up (16:13, 0%, 84Mb, <21539>)
child-21542 ................. up (16:13, 0%, 93Mb, <21542>)
child-21545 ................. up (16:13, 0%, 89Mb, <21545>)
child-21548 ................. up (16:13, 0%, 107Mb, <21548>)
child-21550 ................. up (16:13, 0%, 85Mb, <21550>)
child-21554 ................. up (16:13, 0%, 141Mb, <21554>)
child-21557 ................. up (16:13, 0%, 80Mb, <21557>)
child-21559 ................. up (16:13, 0%, 90Mb, <21559>)
Golang
By adone
Golang
- 1,083