repo stringlengths 6 47 | file_url stringlengths 77 269 | file_path stringlengths 5 186 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-07 08:35:43 2026-01-07 08:55:24 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.6/switch_type_check/main.go | fa/code/src/apps/ch.2.6/switch_type_check/main.go | package main
import (
"fmt"
"strconv"
)
type Element interface{}
type List []Element
type Person struct {
name string
age int
}
func (p Person) String() string {
return "(name: " + p.name + " - age: " + strconv.Itoa(p.age) + " years)"
}
func main() {
list := make(List, 3)
list[0] = 1 ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.6/reflection/main.go | fa/code/src/apps/ch.2.6/reflection/main.go | package main
import (
"fmt"
"reflect"
)
func show_interface_none() {
fmt.Println("\nshow_interface_none()")
var a interface{}
a = "string"
a = 1
a = false
fmt.Println("a =", a)
}
func show_reflection() {
fmt.Println("\nshow_reflection()")
var x float64 = 3.4
v := reflect.ValueOf(x)
fmt.Println("type:", v.... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.6/interface/main.go | fa/code/src/apps/ch.2.6/interface/main.go | package main
import "fmt"
type Human struct {
name string
age int
phone string
}
type Student struct {
Human
school string
loan float32
}
type Employee struct {
Human
company string
money float32
}
func (h Human) SayHi() {
fmt.Printf("Hi, I am %s you can call me on %s\n", h... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.6/stringer_interface/main.go | fa/code/src/apps/ch.2.6/stringer_interface/main.go | package main
import (
"fmt"
"strconv"
)
type Human struct {
name string
age int
phone string
}
// Human implemented fmt.Stringer
func (h Human) String() string {
return "Name:" + h.name + ", Age:" + strconv.Itoa(h.age) + " years, Contact:" + h.phone
}
func main() {
Bob := Human{"Bob", 39, "000-7777-XXX"}
... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.6/type_check/main.go | fa/code/src/apps/ch.2.6/type_check/main.go | package main
import (
"fmt"
"strconv"
)
type Element interface{}
type List []Element
type Person struct {
name string
age int
}
func (p Person) String() string {
return "(name: " + p.name + " - age: " + strconv.Itoa(p.age) + " years)"
}
func main() {
list := make(List, 3)
list[0] = ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.3.2/main.go | fa/code/src/apps/ch.3.2/main.go | // Example code for Chapter 3.2 from "Build Web Application with Golang"
// Purpose: Shows how to acces the form values from the request
package main
import (
"fmt"
"log"
"net/http"
"strings"
)
func sayhelloName(w http.ResponseWriter, r *http.Request) {
r.ParseForm() // parse arguments, you have to call th... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.4.2/main.go | fa/code/src/apps/ch.4.2/main.go | // Example code for Chapter 4.2 from "Build Web Application with Golang"
// Purpose: Shows how to perform server-side validation of user input from a form.
// Also shows to use multiple template files with predefined template names.
// Run `go run main.go` and then access http://localhost:9090
package main
import (
"... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.4.2/validator/main.go | fa/code/src/apps/ch.4.2/validator/main.go | // This file contains all the validators to validate the profile page.
package validator
import (
"errors"
"fmt"
"net/url"
"regexp"
"strconv"
"strings"
"time"
)
type ProfilePage struct {
Form *url.Values
}
type Errors struct {
Errors []error
}
// Goes through the form object and validates each element.
// A... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.2/main.go | fa/code/src/apps/ch.2.2/main.go | // Example code for Chapter 2.2 from "Build Web Application with Golang"
// Purpose: Goes over the assignment and manipulation of basic data types.
package main
import (
"errors"
"fmt"
)
// constants
const Pi = 3.1415926
// booleans default to `false`
var isActive bool // global variable
var enab... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.2/what_is_wrong_with_this/main.go | fa/code/src/apps/ch.2.2/what_is_wrong_with_this/main.go | // Example code for Chapter 2.2 from "Build Web Application with Golang"
// Purpose: Try to fix this program.
// From the console, type `go run main.go`
package main
func main() {
var i int
}
| go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.4/main.go | fa/code/src/apps/ch.2.4/main.go | // Example code for Chapter 2.4 from "Build Web Application with Golang"
// Purpose: Shows different ways of creating a struct
package main
import "fmt"
func show_basic_struct() {
fmt.Println("\nshow_basic_struct()")
type person struct {
name string
age int
}
var P person // p is person type
P.name = "Ast... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.4/embedded_structs_with_name_conflict/main.go | fa/code/src/apps/ch.2.4/embedded_structs_with_name_conflict/main.go | // Example code for Chapter 2.4 from "Build Web Application with Golang"
// Purpose: Shows a name conflict with a embedded field
package main
import "fmt"
type Human struct {
name string
age int
phone string // Human has phone field
}
type Employee struct {
Human // embedded field Human
speciality strin... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.4/embedded_structs/main.go | fa/code/src/apps/ch.2.4/embedded_structs/main.go | // Example code for Chapter 2.4 from "Build Web Application with Golang"
// Purpose: Example of embedded fields
package main
import "fmt"
type Human struct {
name string
age int
weight int
}
type Student struct {
Human // anonymous field, it means Student struct includes all fields that Human has.
spe... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.4/compare_age/main.go | fa/code/src/apps/ch.2.4/compare_age/main.go | // Example code for Chapter 2.4 from "Build Web Application with Golang"
// Purpose: Shows you how to pass and use structs.
package main
import "fmt"
// define a new type
type person struct {
name string
age int
}
// compare age of two people, return the older person and differences of age
// struct is passed by ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/apps/ch.2.4/embedded_structs2/main.go | fa/code/src/apps/ch.2.4/embedded_structs2/main.go | // Example code for Chapter 2.4 from "Build Web Application with Golang"
// Purpose: Another example of embedded fields
package main
import "fmt"
type Skills []string
type Human struct {
name string
age int
weight int
}
type Student struct {
Human // struct as embedded field
Skills // string slic... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/fa/code/src/mymath/sqrt.go | fa/code/src/mymath/sqrt.go | // Example code for Chapter 1.2 from "Build Web Application with Golang"
// Purpose: Shows how to create a simple package called `mymath`
// This package must be imported from another go file to run.
package mymath
func Sqrt(x float64) float64 {
z := 0.0
for i := 0; i < 1000; i++ {
z -= (z*z - x) / (2 * x)
}
ret... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/zh-tw/a_herf.go | zh-tw/a_herf.go | package main
import(
"fmt"
"log"
"os"
"path/filepath"
"sort"
)
func dir()([]string,error) {
path, err := os.Getwd()
if err != nil {
fmt.Println("err is:", err)
}
log.Println(path)
path =path +"/*.html"
fmt.Println(path)
files,err := filepath.Glob(path)
var s... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/zh-tw/build.go | zh-tw/build.go | package main
import (
"bufio"
"fmt"
"github.com/a8m/mark"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
)
// 定义一个访问者结构体
type Visitor struct{}
func (self *Visitor) md2html(arg map[string]string) error {
from := arg["from"]
to := arg["to"]
s := `<meta http-equiv="Content-Type" content="text/html; char... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/zh-tw/build_new.go | zh-tw/build_new.go | package main
import (
"fmt"
"io/ioutil"
"bufio"
"net/http"
"os"
"path/filepath"
"regexp"
"strings"
)
// 开发者 GitHub token
const token = ""
// 定义一个访问者结构体
type Visitor struct{}
func (self *Visitor) md2html(arg map[string]string) error {
from := arg["from"]
to := arg["to"]
s := `<meta http-equiv="Content-Typ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/zh-tw/src/1.2/sqrt.go | zh-tw/src/1.2/sqrt.go | // 章節 1.2
// $GOPATH/src/mymath/sqrt.go
package mymath
func Sqrt(x float64) float64 {
z := 0.0
for i := 0; i < 1000; i++ {
z -= (z*z - x) / (2 * x)
}
return z
}
| go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/zh-tw/src/1.2/main.go | zh-tw/src/1.2/main.go | // 章節 1.2
// $GOPATH/src/mathapp/main.go
package main
import (
"fmt"
"mymath"
)
func main() {
fmt.Printf("Hello, world. Sqrt(2) = %v\n", mymath.Sqrt(2))
}
| go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/es/code/src/apps/ch.1.2/main.go | es/code/src/apps/ch.1.2/main.go | // Código de ejemplo para el capítulo 1.2 del libro "Construye Aplicaciones Web con Golang"
// Propósito: Ejecuta este archivo para verificar que tu espacio de trabajo está configurado correctamente.
// Para ejecutarlo, busca el directorio actual en la terminal y escribe `go run main.go`
// Si el texto "Hello World" no... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/es/code/src/mymath/sqrt.go | es/code/src/mymath/sqrt.go | // Código de ejmplo para el capítulo 1.2 de "Construye Aplicaciones Web con Golang"
// Propósito: Muestra como crear un paquete simple llamado `mymath`
// Este paquete debe ser importado desde otro archivo Go para poder ejecutarse.
package mymath
func Sqrt(x float64) float64 {
z := 0.0
for i := 0; i < 1000; i++ {
... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.5.4/main.go | pt-br/code/src/apps/ch.5.4/main.go | // Example code for Chapter 5.4 from "Build Web Application with Golang"
// Purpose: Show how to perform CRUD operations using a postgres driver
package main
import (
"database/sql"
"fmt"
"time"
_ "github.com/lib/pq"
)
const (
DB_USER = "user"
DB_PASSWORD = ""
DB_NAME = "test"
)
func main() {
dbinfo... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.1/main.go | pt-br/code/src/apps/ch.4.1/main.go | // Example code for Chapter 4.1 from "Build Web Application with Golang"
// Purpose: Shows how to create a simple login using a template
// Run: `go run main.go`, then access `http://localhost:9090` and `http://localhost:9090/login`
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"strings"
)
func sa... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.5.5/main.go | pt-br/code/src/apps/ch.5.5/main.go | // Example code for Chapter 5.5
// Purpose is to show to use BeeDB ORM for basic CRUD operations for sqlite3
package main
import (
"database/sql"
"fmt"
"github.com/astaxie/beedb"
_ "github.com/mattn/go-sqlite3"
"time"
)
var orm beedb.Model
type Userinfo struct {
Uid int `beedb:"PK"`
Username string
... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.1/main.go | pt-br/code/src/apps/ch.2.1/main.go | // Código de exemplo para o Capítulo 2.1 do "Build Web Application with Golang"
// Propósito: Exemplo de Hello world demonstrando suporte para UTF-8.
// Para executar, navegue até o diretório onde ele estiver salvo e digite no console `go run main.go`
// Se você receber quadrados ou pontos de interrogação, possivelemen... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.5/main.go | pt-br/code/src/apps/ch.4.5/main.go | // Example code for Chapter 4.5
// Purpose is to create a server to handle uploading files.
package main
import (
"apps/ch.4.4/nonce"
"apps/ch.4.4/validator"
"fmt"
"html/template"
"io"
"mime/multipart"
"net/http"
"os"
)
const MiB_UNIT = 1 << 20
var t *template.Template
var submissions nonce.Nonces = nonce.Ne... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.5/nonce/main.go | pt-br/code/src/apps/ch.4.5/nonce/main.go | // A nonce is a number or string used only once.
// This is useful for generating a unique token for login pages to prevent duplicate submissions.
package nonce
import (
"crypto/md5"
"errors"
"fmt"
"io"
"math/rand"
"strconv"
"time"
)
// Contains a unique token
type Nonce struct {
Token string
}
// Keeps trac... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.5/validator/main.go | pt-br/code/src/apps/ch.4.5/validator/main.go | // This file contains all the validators to validate the profile page.
package validator
import (
"errors"
"fmt"
"net/url"
"regexp"
"strconv"
"strings"
"time"
)
type ProfilePage struct {
Form *url.Values
}
type Errors struct {
Errors []error
}
// Goes through the form object and validates each element.
// A... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.5/client_upload/main.go | pt-br/code/src/apps/ch.4.5/client_upload/main.go | package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"os"
)
func checkError(err error) {
if err != nil {
panic(err)
}
}
func postFile(filename string, targetUrl string) {
bodyBuf := &bytes.Buffer{}
bodyWriter := multipart.NewWriter(bodyBuf)
fileWriter, err := bodyWriter.Creat... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.5.3/main.go | pt-br/code/src/apps/ch.5.3/main.go | // Example code for Chapter 5.3 from "Build Web Application with Golang"
// Purpose: Shows how to run simple CRUD operations using a sqlite driver
package main
import (
"database/sql"
"fmt"
_ "github.com/mattn/go-sqlite3"
"time"
)
const DB_PATH = "./foo.db"
func main() {
db, err := sql.Open("sqlite3", DB_PATH)
... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.4/main.go | pt-br/code/src/apps/ch.4.4/main.go | // Example code for Chapter 3.2 from "Build Web Application with Golang"
// Purpose: Shows how to prevent duplicate submissions by using tokens
// Example code for Chapter 4.4 based off the code from Chapter 4.2
// Run `go run main.go` then access http://localhost:9090
package main
import (
"apps/ch.4.4/nonce"
"apps... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.4/nonce/main.go | pt-br/code/src/apps/ch.4.4/nonce/main.go | // A nonce is a number or string used only once.
// This is useful for generating a unique token for login pages to prevent duplicate submissions.
package nonce
import (
"crypto/md5"
"errors"
"fmt"
"io"
"math/rand"
"strconv"
"time"
)
// Contains a unique token
type Nonce struct {
Token string
}
// Keeps trac... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.4/validator/main.go | pt-br/code/src/apps/ch.4.4/validator/main.go | // This file contains all the validators to validate the profile page.
package validator
import (
"errors"
"fmt"
"net/url"
"regexp"
"strconv"
"strings"
"time"
)
type ProfilePage struct {
Form *url.Values
}
type Errors struct {
Errors []error
}
// Goes through the form object and validates each element.
// A... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.5.2/main.go | pt-br/code/src/apps/ch.5.2/main.go | // Example code for Chapter 5.2 from "Build Web Application with Golang"
// Purpose: Use SQL driver to perform simple CRUD operations.
package main
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
const (
DB_USER = "user"
DB_PASSWORD = ""
DB_NAME = "test"
)
func main() {
dbSouce := f... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/main.go | pt-br/code/src/apps/ch.2.3/main.go | // Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra alguns exemplos de if, else, switch, loops e defer.
package main
import "fmt"
func computedValue() int {
return 1
}
func show_if() {
fmt.Println("\n#show_if()")
x := computedValue()
integer := 23
fmt.Println("x =", ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/import_packages/main.go | pt-br/code/src/apps/ch.2.3/import_packages/main.go | // Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra diferentes formas de importar um pacote.
// Nota: para o pacote `only_call_init`, fazemos referência ao caminho a partir do diretório
// base de `$GOPATH/src`. Golang desencoraja o uso de caminhos relativos para importar pa... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/import_packages/only_call_init/only_call_init.go | pt-br/code/src/apps/ch.2.3/import_packages/only_call_init/only_call_init.go | package only_call_init
import "fmt"
func init() {
fmt.Println("only_call_init.init() was called.")
}
| go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/type_function/main.go | pt-br/code/src/apps/ch.2.3/type_function/main.go | // Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra como definir um tipo de função
package main
import "fmt"
type testInt func(int) bool // define uma função como um tipo de variável
func isOdd(integer int) bool {
if integer%2 == 0 {
return false
}
return true
}
fun... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/variadic_functions/main.go | pt-br/code/src/apps/ch.2.3/variadic_functions/main.go | // Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra como retornar múltiplos valores de uma função
package main
import "fmt"
// retorna os resultados de A + B e A * B
func SumAndProduct(A, B int) (int, int) {
return A + B, A * B
}
func main() {
x := 3
y := 4
xPLUSy, x... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/hidden_print_methods/main.go | pt-br/code/src/apps/ch.2.3/hidden_print_methods/main.go | // A partir do Google go 1.1.2, `println()` e `print()` são funções ocultas incluídas no pacote de tempo de execução.
// No entanto, é encorajado utilizar as funções de impressão do pacote `fmt`
package main
import "fmt"
func f() {
fmt.Println("First")
print("Second ")
println(" Third")
}
func main() {
f()
}
| go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/panic_and_recover/main.go | pt-br/code/src/apps/ch.2.3/panic_and_recover/main.go | // Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostrar como usar `panic()` e `recover()`
package main
import (
"fmt"
"os"
)
var user = os.Getenv("USER")
func check_user() {
if user == "" {
panic("no value for $USER")
}
fmt.Println("Environment Variable `USER` =", use... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/basic_functions/main.go | pt-br/code/src/apps/ch.2.3/basic_functions/main.go | // Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: Criando uma função básica
package main
import "fmt"
// retorna o maior valor entre a e b
func max(a, b int) int {
if a > b {
return a
}
return b
}
func main() {
x := 3
y := 4
z := 5
max_xy := max(x, y) // chama a funç... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.3/pass_by_value_and_pointer/main.go | pt-br/code/src/apps/ch.2.3/pass_by_value_and_pointer/main.go | // Código de exemplo do capítulo 2.3 de "Build Web Application with Golang"
// Propósito: mostra como passar uma variável por valor e por referência
package main
import "fmt"
func add_by_value(a int) int {
a = a + 1
return a
}
func add_by_reference(a *int) int {
*a = *a + 1
return *a
}
func show_add_by_value(... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.3/main.go | pt-br/code/src/apps/ch.4.3/main.go | // Example code for Chapter 4.3 from "Build Web Application with Golang"
// Purpose: Shows how to properly escape input
package main
import (
"html/template"
"net/http"
textTemplate "text/template"
)
var t *template.Template = template.Must(template.ParseFiles("index.gtpl"))
func index(w http.ResponseWriter, r *h... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.1.2/main.go | pt-br/code/src/apps/ch.1.2/main.go | // Código de exemplo para o Capítulo 1.2 do "Build Web Application with Golang"
// Propósito: Execute este arquivo para verificar se o seu workspace está corretamente configurado.
// Para executar, navegue até o diretório onde ele estiver salvo e digite no console `go run main.go`
// Se o texto "Hello World" não aparec... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.7/select_channel/main.go | pt-br/code/src/apps/ch.2.7/select_channel/main.go | // Example code for Chapter 2.7 from "Build Web Application with Golang"
// Purpose: Shows how to use `select`
package main
import "fmt"
func fibonacci(c, quit chan int) {
x, y := 1, 1
for {
select {
case c <- x:
x, y = y, x+y
case <-quit:
fmt.Println("quit")
return
}
}
}
func main() {
c := make... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.7/buffered_channel/main.go | pt-br/code/src/apps/ch.2.7/buffered_channel/main.go | // Example code for Chapter 2.7 from "Build Web Application with Golang"
// Purpose: Shows how to use a buffered channel
package main
import "fmt"
func main() {
c := make(chan int, 2) // change 2 to 1 will have runtime error, but 3 is fine
c <- 1
c <- 2
fmt.Println(<-c)
fmt.Println(<-c)
}
| go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.7/goroutine/main.go | pt-br/code/src/apps/ch.2.7/goroutine/main.go | // Example code for Chapter 2.7 from "Build Web Application with Golang"
// Purpose: Shows how to launch a simple gorountine
package main
import (
"fmt"
"runtime"
)
func say(s string) {
for i := 0; i < 5; i++ {
runtime.Gosched()
fmt.Println(s)
}
}
func main() {
go say("world") // create a new goroutine
say... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.7/range_and_close_channel/main.go | pt-br/code/src/apps/ch.2.7/range_and_close_channel/main.go | // Example code for Chapter 2.7 from "Build Web Application with Golang"
// Purpose: Shows how to close and interate through a channel
package main
import (
"fmt"
)
func fibonacci(n int, c chan int) {
x, y := 1, 1
for i := 0; i < n; i++ {
c <- x
x, y = y, x+y
}
close(c)
}
func main() {
c := make(chan int, ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.7/unbuffered_channel/main.go | pt-br/code/src/apps/ch.2.7/unbuffered_channel/main.go | // Example code for Chapter 2.7 from "Build Web Application with Golang"
// Purpose: Shows how to create and use a unbuffered channel
package main
import "fmt"
func sum(a []int, c chan int) {
total := 0
for _, v := range a {
total += v
}
c <- total // send total to c
}
func main() {
a := []int{7, 2, 8, -9, 4,... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.7/timeout/main.go | pt-br/code/src/apps/ch.2.7/timeout/main.go | // Example code for Chapter 2.7 from "Build Web Application with Golang"
// Purpose: Shows how to create and use a timeout
package main
import (
"fmt"
"time"
)
func main() {
c := make(chan int)
o := make(chan bool)
go func() {
for {
select {
case v := <-c:
fmt.Println(v)
case <-time.After(5 * tim... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.3.4/main.go | pt-br/code/src/apps/ch.3.4/main.go | // Example code for Chapter 3.4 from "Build Web Application with Golang"
// Purpose: Shows how to create a handler for `http.ListenAndServe()`
// Run `go run main.go` then access `http://localhost:9090`
package main
import (
"fmt"
"net/http"
)
type MyMux struct {
}
func (p *MyMux) ServeHTTP(w http.ResponseWriter, ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.5.6/mongodb/main.go | pt-br/code/src/apps/ch.5.6/mongodb/main.go | // Example code for Chapter 5.6 from "Build Web Application with Golang"
// Purpose: Shows you have to perform basic CRUD operations for a mongodb driver.
package main
import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
)
type Person struct {
Name string
Phone string
}
func checkError(err error) {
if er... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.5.6/redis/main.go | pt-br/code/src/apps/ch.5.6/redis/main.go | // Example code for Chapter 5.6 from "Build Web Application with Golang"
// Purpose: Shows you have to perform basic CRUD operations for a redis driver.
package main
import (
"fmt"
"github.com/astaxie/goredis"
)
func checkError(err error) {
if err != nil {
panic(err)
}
}
const (
DB_PORT = "9191"
DB_URL = "1... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.5/attach_methods_to_struct/main.go | pt-br/code/src/apps/ch.2.5/attach_methods_to_struct/main.go | // Example code from Chapter 2.5
// Attach method to struct.
package main
import (
"fmt"
"math"
)
type Rectangle struct {
width, height float64
}
type Circle struct {
radius float64
}
func (r Rectangle) area() float64 {
return r.width * r.height
}
func (c Circle) area() float64 {
return c.radius * c.radius *... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.5/method_overload/main.go | pt-br/code/src/apps/ch.2.5/method_overload/main.go | package main
import "fmt"
type Human struct {
name string
age int
phone string
}
type Student struct {
Human
school string
}
type Employee struct {
Human
company string
}
func (h *Human) SayHi() {
fmt.Printf("Hi, I am %s you can call me on %s\n", h.name, h.phone)
}
func (e *Employee) SayHi() {
fmt.Pri... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.5/pass_struct_to_method/main.go | pt-br/code/src/apps/ch.2.5/pass_struct_to_method/main.go | package main
import "fmt"
type Rectangle struct {
width, height float64
}
func area(r Rectangle) float64 {
return r.width * r.height
}
func main() {
r1 := Rectangle{12, 2}
r2 := Rectangle{9, 4}
fmt.Println("Area of r1 is: ", area(r1))
fmt.Println("Area of r2 is: ", area(r2))
}
| go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.5/box_example/main.go | pt-br/code/src/apps/ch.2.5/box_example/main.go | package main
import "fmt"
const (
WHITE = iota
BLACK
BLUE
RED
YELLOW
)
type Color byte
type Box struct {
width, height, depth float64
color Color
}
type BoxList []Box //a slice of boxes
func (b Box) Volume() float64 {
return b.width * b.height * b.depth
}
func (b *Box) SetColor(c Color) {
... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.5/embedded_method/main.go | pt-br/code/src/apps/ch.2.5/embedded_method/main.go | package main
import "fmt"
type Human struct {
name string
age int
phone string
}
type Student struct {
Human // anonymous field
school string
}
type Employee struct {
Human
company string
}
// define a method in Human
func (h *Human) SayHi() {
fmt.Printf("Hi, I am %s you can call me... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.6/switch_type_check/main.go | pt-br/code/src/apps/ch.2.6/switch_type_check/main.go | package main
import (
"fmt"
"strconv"
)
type Element interface{}
type List []Element
type Person struct {
name string
age int
}
func (p Person) String() string {
return "(name: " + p.name + " - age: " + strconv.Itoa(p.age) + " years)"
}
func main() {
list := make(List, 3)
list[0] = 1 ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.6/reflection/main.go | pt-br/code/src/apps/ch.2.6/reflection/main.go | package main
import (
"fmt"
"reflect"
)
func show_interface_none() {
fmt.Println("\nshow_interface_none()")
var a interface{}
a = "string"
a = 1
a = false
fmt.Println("a =", a)
}
func show_reflection() {
fmt.Println("\nshow_reflection()")
var x float64 = 3.4
v := reflect.ValueOf(x)
fmt.Println("type:", v.... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.6/interface/main.go | pt-br/code/src/apps/ch.2.6/interface/main.go | package main
import "fmt"
type Human struct {
name string
age int
phone string
}
type Student struct {
Human
school string
loan float32
}
type Employee struct {
Human
company string
money float32
}
func (h Human) SayHi() {
fmt.Printf("Hi, I am %s you can call me on %s\n", h... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.6/stringer_interface/main.go | pt-br/code/src/apps/ch.2.6/stringer_interface/main.go | package main
import (
"fmt"
"strconv"
)
type Human struct {
name string
age int
phone string
}
// Human implemented fmt.Stringer
func (h Human) String() string {
return "Name:" + h.name + ", Age:" + strconv.Itoa(h.age) + " years, Contact:" + h.phone
}
func main() {
Bob := Human{"Bob", 39, "000-7777-XXX"}
... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.6/type_check/main.go | pt-br/code/src/apps/ch.2.6/type_check/main.go | package main
import (
"fmt"
"strconv"
)
type Element interface{}
type List []Element
type Person struct {
name string
age int
}
func (p Person) String() string {
return "(name: " + p.name + " - age: " + strconv.Itoa(p.age) + " years)"
}
func main() {
list := make(List, 3)
list[0] = ... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.3.2/main.go | pt-br/code/src/apps/ch.3.2/main.go | // Example code for Chapter 3.2 from "Build Web Application with Golang"
// Purpose: Shows how to acces the form values from the request
package main
import (
"fmt"
"log"
"net/http"
"strings"
)
func sayhelloName(w http.ResponseWriter, r *http.Request) {
r.ParseForm() // parse arguments, you have to call th... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.2/main.go | pt-br/code/src/apps/ch.4.2/main.go | // Example code for Chapter 4.2 from "Build Web Application with Golang"
// Purpose: Shows how to perform server-side validation of user input from a form.
// Also shows to use multiple template files with predefined template names.
// Run `go run main.go` and then access http://localhost:9090
package main
import (
"... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.4.2/validator/main.go | pt-br/code/src/apps/ch.4.2/validator/main.go | // This file contains all the validators to validate the profile page.
package validator
import (
"errors"
"fmt"
"net/url"
"regexp"
"strconv"
"strings"
"time"
)
type ProfilePage struct {
Form *url.Values
}
type Errors struct {
Errors []error
}
// Goes through the form object and validates each element.
// A... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.2/main.go | pt-br/code/src/apps/ch.2.2/main.go | // Código de exemplo para o Capítulo 2.2 do "Build Web Application with Golang"
// Propósito: Revisar os conceitos de atribuição e manipulação de tipos de dados básicos.
package main
import (
"errors"
"fmt"
)
// constantes
const Pi = 3.1415926
// booleanos: padrão `false`
var isActive bool // var... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.2/what_is_wrong_with_this/main.go | pt-br/code/src/apps/ch.2.2/what_is_wrong_with_this/main.go | // Código de exemplo para o Capítulo 2.2 do "Build Web Application with Golang"
// Propósito: Tente corrigir este programa.
// No console, digite `go run main.go`
package main
func main() {
var i int
}
| go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.4/main.go | pt-br/code/src/apps/ch.2.4/main.go | // Código de exemplo da seção 2.4 de "Build Web Application with Golang"
// Propósito: Mostrar formas diferentes de criar uma estrutura
package main
import "fmt"
func show_basic_struct() {
fmt.Println("\nshow_basic_struct()")
type person struct {
name string
age int
}
var P person // p é do tipo person
P.... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.4/embedded_structs_with_name_conflict/main.go | pt-br/code/src/apps/ch.2.4/embedded_structs_with_name_conflict/main.go | // Código de exemplo da seção 2.4 de "Build Web Application with Golang"
// Propósito: Mostra um conflito de nomes com um campo incorporado
package main
import "fmt"
type Human struct {
name string
age int
phone string // Human possui campo phone
}
type Employee struct {
Human // campo incorporado de Hum... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.4/embedded_structs/main.go | pt-br/code/src/apps/ch.2.4/embedded_structs/main.go | // Código de exemplo da seção 2.4 de "Build Web Application with Golang"
// Propósito: Exemplo de campos incorporados
package main
import "fmt"
type Human struct {
name string
age int
weight int
}
type Student struct {
Human // campo anônimo, significa que a estrutura Student inclui todos os campos que... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.4/compare_age/main.go | pt-br/code/src/apps/ch.2.4/compare_age/main.go | // Código de exemplo da seção 2.4 de "Build Web Application with Golang"
// Propósito: Mostrar como utilizar estruturas em Go.
package main
import "fmt"
// define um novo tipo
type person struct {
name string
age int
}
// compara a idade de duas pessoas e retorna dois valores: a pessoa mais velha e a diferença de... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/apps/ch.2.4/embedded_structs2/main.go | pt-br/code/src/apps/ch.2.4/embedded_structs2/main.go | // Código de exemplo da seção 2.4 de "Build Web Application with Golang"
// Propósito: Outro exemplo de campos incorporados
package main
import "fmt"
type Skills []string
type Human struct {
name string
age int
weight int
}
type Student struct {
Human // estrutura como campo incorporado
Skills //... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
astaxie/build-web-application-with-golang | https://github.com/astaxie/build-web-application-with-golang/blob/c294b087b96d99d2593ad8f470151af5354bb57f/pt-br/code/src/mymath/sqrt.go | pt-br/code/src/mymath/sqrt.go | // Example code for Chapter 1.2 from "Build Web Application with Golang"
// Purpose: Shows how to create a simple package called `mymath`
// This package must be imported from another go file to run.
package mymath
func Sqrt(x float64) float64 {
z := 0.0
for i := 0; i < 1000; i++ {
z -= (z*z - x) / (2 * x)
}
ret... | go | BSD-3-Clause | c294b087b96d99d2593ad8f470151af5354bb57f | 2026-01-07T08:35:46.175972Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/key_other.go | key_other.go | //go:build !windows
// +build !windows
package tea
import (
"context"
"io"
)
func readInputs(ctx context.Context, msgs chan<- Msg, input io.Reader) error {
return readAnsiInputs(ctx, msgs, input)
}
| go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/exec.go | exec.go | package tea
import (
"io"
"os"
"os/exec"
)
// execMsg is used internally to run an ExecCommand sent with Exec.
type execMsg struct {
cmd ExecCommand
fn ExecCallback
}
// Exec is used to perform arbitrary I/O in a blocking fashion, effectively
// pausing the Program while execution is running and resuming it wh... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/nil_renderer.go | nil_renderer.go | package tea
type nilRenderer struct{}
func (n nilRenderer) start() {}
func (n nilRenderer) stop() {}
func (n nilRenderer) kill() {}
func (n nilRenderer) write(_ string) {}
func (n nilRenderer) repaint() {}
func (n nilRenderer)... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/mouse.go | mouse.go | package tea
import "strconv"
// MouseMsg contains information about a mouse event and are sent to a programs
// update function when mouse activity occurs. Note that the mouse must first
// be enabled in order for the mouse events to be received.
type MouseMsg MouseEvent
// String returns a string representation of ... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/tea_test.go | tea_test.go | package tea
import (
"bytes"
"context"
"errors"
"sync"
"sync/atomic"
"testing"
"time"
)
type ctxImplodeMsg struct {
cancel context.CancelFunc
}
type incrementMsg struct{}
type panicMsg struct{}
func panicCmd() Msg {
panic("testing goroutine panic behavior")
}
type testModel struct {
executed atomic.Valu... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/key_test.go | key_test.go | package tea
import (
"bytes"
"context"
"errors"
"flag"
"fmt"
"io"
"math/rand"
"reflect"
"runtime"
"sort"
"strings"
"sync"
"testing"
"time"
)
func TestKeyString(t *testing.T) {
t.Run("alt+space", func(t *testing.T) {
if got := KeyMsg(Key{
Type: KeySpace,
Alt: true,
}).String(); got != "alt+ "... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/commands.go | commands.go | package tea
import (
"time"
)
// Batch performs a bunch of commands concurrently with no ordering guarantees
// about the results. Use a Batch to return several commands.
//
// Example:
//
// func (m model) Init() Cmd {
// return tea.Batch(someCommand, someOtherCommand)
// }
func Batch(cmds ...Cmd) C... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/logging.go | logging.go | package tea
import (
"fmt"
"io"
"log"
"os"
"unicode"
)
// LogToFile sets up default logging to log to a file. This is helpful as we
// can't print to the terminal since our TUI is occupying it. If the file
// doesn't exist it will be created.
//
// Don't forget to close the file when you're done with it.
//
// ... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/mouse_test.go | mouse_test.go | package tea
import (
"fmt"
"testing"
)
func TestMouseEvent_String(t *testing.T) {
tt := []struct {
name string
event MouseEvent
expected string
}{
{
name: "unknown",
event: MouseEvent{
Action: MouseActionPress,
Button: MouseButtonNone,
Type: MouseUnknown,
},
expected: "unk... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/renderer.go | renderer.go | package tea
// renderer is the interface for Bubble Tea renderers.
type renderer interface {
// Start the renderer.
start()
// Stop the renderer, but render the final frame in the buffer, if any.
stop()
// Stop the renderer without doing any final rendering.
kill()
// Write a frame to the renderer. The rende... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/screen.go | screen.go | package tea
// WindowSizeMsg is used to report the terminal size. It's sent to Update once
// initially and then on every terminal resize. Note that Windows does not
// have support for reporting when resizes occur as it does not support the
// SIGWINCH signal.
type WindowSizeMsg struct {
Width int
Height int
}
//... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/nil_renderer_test.go | nil_renderer_test.go | package tea
import "testing"
func TestNilRenderer(t *testing.T) {
r := nilRenderer{}
r.start()
r.stop()
r.kill()
r.write("a")
r.repaint()
r.enterAltScreen()
if r.altScreen() {
t.Errorf("altScreen should always return false")
}
r.exitAltScreen()
r.clearScreen()
r.showCursor()
r.hideCursor()
r.enableMou... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/inputreader_windows.go | inputreader_windows.go | //go:build windows
// +build windows
package tea
import (
"fmt"
"io"
"os"
"sync"
"github.com/charmbracelet/x/term"
"github.com/erikgeiser/coninput"
"github.com/muesli/cancelreader"
"golang.org/x/sys/windows"
)
type conInputReader struct {
cancelMixin
conin windows.Handle
originalMode uint32
}
var _ ca... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/standard_renderer.go | standard_renderer.go | package tea
import (
"bytes"
"fmt"
"io"
"strings"
"sync"
"time"
"github.com/charmbracelet/x/ansi"
"github.com/muesli/ansi/compressor"
)
const (
// defaultFramerate specifies the maximum interval at which we should
// update the view.
defaultFPS = 60
maxFPS = 120
)
// standardRenderer is a framerate-... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/screen_test.go | screen_test.go | package tea
import (
"bytes"
"testing"
)
func TestClearMsg(t *testing.T) {
tests := []struct {
name string
cmds sequenceMsg
expected string
}{
{
name: "clear_screen",
cmds: []Cmd{ClearScreen},
expected: "\x1b[?25l\x1b[?2004h\x1b[2J\x1b[H\rsuccess\x1b[K\r\n\x1b[K\r\x1b[2K\r\x1b[?20... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/tea.go | tea.go | // Package tea provides a framework for building rich terminal user interfaces
// based on the paradigms of The Elm Architecture. It's well-suited for simple
// and complex terminal applications, either inline, full-window, or a mix of
// both. It's been battle-tested in several large projects and is
// production-read... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/tty.go | tty.go | package tea
import (
"errors"
"fmt"
"io"
"time"
"github.com/charmbracelet/x/term"
"github.com/muesli/cancelreader"
)
func (p *Program) suspend() {
if err := p.ReleaseTerminal(); err != nil {
// If we can't release input, abort.
return
}
suspendProcess()
_ = p.RestoreTerminal()
go p.Send(ResumeMsg{})... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/exec_test.go | exec_test.go | package tea
import (
"bytes"
"os/exec"
"runtime"
"testing"
)
type execFinishedMsg struct{ err error }
type testExecModel struct {
cmd string
err error
}
func (m testExecModel) Init() Cmd {
c := exec.Command(m.cmd) //nolint:gosec
return ExecProcess(c, func(err error) Msg {
return execFinishedMsg{err}
})
}... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/signals_windows.go | signals_windows.go | //go:build windows
// +build windows
package tea
// listenForResize is not available on windows because windows does not
// implement syscall.SIGWINCH.
func (p *Program) listenForResize(done chan struct{}) {
close(done)
}
| go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/key_sequences.go | key_sequences.go | package tea
import (
"bytes"
"sort"
"unicode/utf8"
)
// extSequences is used by the map-based algorithm below. It contains
// the sequences plus their alternatives with an escape character
// prefixed, plus the control chars, plus the space.
// It does not contain the NUL character, which is handled specially
// b... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/commands_test.go | commands_test.go | package tea
import (
"fmt"
"testing"
"time"
)
func TestEvery(t *testing.T) {
expected := "every ms"
msg := Every(time.Millisecond, func(t time.Time) Msg {
return expected
})()
if expected != msg {
t.Fatalf("expected a msg %v but got %v", expected, msg)
}
}
func TestTick(t *testing.T) {
expected := "tick... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/signals_unix.go | signals_unix.go | //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || aix || zos
// +build darwin dragonfly freebsd linux netbsd openbsd solaris aix zos
package tea
import (
"os"
"os/signal"
"syscall"
)
// listenForResize sends messages (or errors) when the terminal resizes.
// Argument output sho... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
charmbracelet/bubbletea | https://github.com/charmbracelet/bubbletea/blob/f9233d51192293dadda7184a4de347738606c328/tea_init.go | tea_init.go | package tea
import (
"github.com/charmbracelet/lipgloss"
)
func init() {
// XXX: This is a workaround to make assure that Lip Gloss and Termenv
// query the terminal before any Bubble Tea Program runs and acquires the
// terminal. Without this, Programs that use Lip Gloss/Termenv might hang
// while waiting for ... | go | MIT | f9233d51192293dadda7184a4de347738606c328 | 2026-01-07T08:35:58.083951Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.