Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
cd utils
GOROOT=/home/rekby/Downloads/go/ GOTOOLDIR=/home/rekby/Downloads/go/pkg/tool/linux_amd64/ /home/rekby/Downloads/go/bin/go build
upx utils
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2013
UPX 3.91 Markus Oberhumer, Laszlo Molnar & John Reiser Sep 30th 2013
File size Ratio Format Name
-------------------- ------ ----------- -----------
upx: utils: EOFException: premature end of file
Packed 1 file: 0 ok, 1 error.
bash-3.2$ cat server.go
package main
import (
"log"
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func (rw http.ResponseWriter, req *http.Request) {
log.Printf("new request")
fmt.Fprintf(rw, "Hello %s", "World")
})
log.Printf("server starting")
http.ListenAndServe(":8080", nil)
}
bash-3.2$ go build -o server server.go
bash-3.2$ ls -l
total 11320
-rwxr-xr-x 1 miolini staff 5790996 Feb 24 15:00 server
-rw-r--r-- 1 miolini wheel 278 Feb 24 15:00 server.go
bash-3.2$ upx --lzma server
Ultimate Packer for eXecutables
Copyright (C) 1996 - 2013
UPX 3.91 Markus Oberhumer, Laszlo Molnar & John Reiser Sep 30th 2013
File size Ratio Format Name
-------------------- ------ ----------- -----------
5790996 -> 1204224 20.79% Mach/AMD64 server
Packed 1 file.
bash-3.2$ ls -l
total 2360
-rwxr-xr-x 1 miolini staff 1204224 Feb 24 15:00 server
-rw-r--r-- 1 miolini wheel 278 Feb 24 15:00 server.go
./any --multiex-command=test asdf вместо ./any test asdf?cat --busybox-command=bash -c ...
func asbb(){
os.Args = os.Args[1:]
multiex.Main()
}
func main(){
multiex.Register(multiex.ExecutorDescribe{Name: "asbb", Function: asbb})
}

go install -buildmode=shared std
go build -linkshared hello.go
package main
import (
"io"
"log"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, string("Hello world"))
})
log.Print("Server started at http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
go install -buildmode=shared std
go build -ldflags "-linkmode external -extldflags -static" hello.go
Although these repositories are often huge it is not possible to have every piece of software in them, so dependency hell can still occur. In all cases, dependency hell is still faced by the repository maintainers.
В таком случае удовлетворение долгой цепи зависимостей пакетов даже может привести, например, к запросу другой версии библиотеки glibc, одной из крайне важных, основополагающих системных библиотек. Если это случается пользователю будет предложено удалить тысячи пакетов, что по сути будет равноценно удалению, например, 80% системы, включая графические оболочки и сотни различных программ.
Если же компилировать микросервисы в один экзешник, то теряются многие плюсы такой структуры. Например, обновления (или, не дай бог, ошибки) одного микросервиса, будут затрагивать все остальные, чего очень хотелось бы, особенно с проектами в активной фазе разработки.
Уменьшение накладных расходов для утилит на golang