//// users/users.go
package users
type user struct {
name string
}
func New(name string) *user {
u := user{
name: name,
}
if name == "" {
u.name = "Nobody"
}
return &u
}
///// main.go
package main
import "github.com/yourproject/users"
func main() {
user := users.New("")
...........
}
go mod init your/module/path
type A struct {
Id string `db:"id" json:"id" valid:"uuidv4"`
Target string `db:"target" json:"target" valid:"uuidv4"`
}
type B struct {
Id string `db:"id" json:"id" valid:"uuidv4"`
Type int `db:"type" json:"type" valid:"-"`
SomeFieldName A `json:"A"`
}
var u []*user
используйте users := make([]*user, 0, 100000)
func RegisterUser(name string, surname string, age int)
type User struct {
Name string
Surname string
Age int
}
func RegisterUser(user User)
In a case or default clause, the last non-empty statement may be a (possibly labeled) "fallthrough" statement to indicate that control should flow from the end of this clause to the first statement of the next clause
for _, field := range fields {
if field.Name() == "fields" {
if field, ok := field.Value().(ExtField); ok {
res[field.Key] = field.Text
}
}
}
package main
import (
"io"
"os"
"os/exec"
"strings"
)
func main() {
resulution := "640x480" // Разрешение видео
framerate := "1" // Частота кадров, здесб нам достаточно 1 кадр в секунду
outfile := "out.webm" // Файл, в который писать, расширение задаст его формат
color1 := "0xFF0000" // RGB (255,0,0)
color2 := "0x00FF00" // RGB (0,255,0)
color3 := "0x0000FF" // RGB (0,0,255)
//////////////////////////////
filtergraph := []string{
"color=c=" + color1 + ":size=" + resulution + ":duration=3:s=qcif:r=" + framerate + " [v1]",
"color=c=" + color2 + ":size=" + resulution + ":duration=3:s=qcif:r=" + framerate + " [v2]",
"color=c=" + color3 + ":size=" + resulution + ":duration=3:s=qcif:r=" + framerate + " [v3]",
`[v1] [v2] [v3] concat=n=3 [v]`,
}
allOptions := []string{
"-filter_complex", strings.Join(filtergraph, ";"),
"-map", "[v]",
"-threads", "0", "-y", outfile,
}
RunCmd("ffmpeg", allOptions...)
}
func ReadAndPrint(r io.Reader) {
io.Copy(os.Stdout, r)
}
func RunCmd(name string, args ...string) {
cmd := exec.Command(name, args...)
stdout, err := cmd.StdoutPipe()
if err != nil {
panic(err)
}
stderr, err := cmd.StderrPipe()
if err != nil {
panic(err)
}
go ReadAndPrint(stdout)
go ReadAndPrint(stderr)
err = cmd.Run()
if err != nil {
panic(err)
}
}
tmpl, _ := template.ParseFiles("")