Compare commits
10 commits
7c5926b97a
...
088fa647f5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
088fa647f5 | ||
|
|
f902723e2c | ||
|
|
694ed7d17a | ||
|
|
2deb237e98 | ||
|
|
96a7ebccde | ||
|
|
75fdb1af46 | ||
|
|
4db600f957 | ||
|
|
d7baf0b099 | ||
|
|
dc40ebd598 | ||
|
|
55225686f1 |
18 changed files with 234 additions and 6 deletions
2
git.sh
2
git.sh
|
|
@ -7,7 +7,7 @@ git commit -m "$com"
|
||||||
declare -A remotes=(
|
declare -A remotes=(
|
||||||
["gitflic"]="git@gitflic.ru:hhu67/proj.git"
|
["gitflic"]="git@gitflic.ru:hhu67/proj.git"
|
||||||
["github"]="git@github.com:hhu67/my.git"
|
["github"]="git@github.com:hhu67/my.git"
|
||||||
["forgejo"]="git@git.vlv-s.site:hhu67/my.git"
|
["forgejo"]="forgejo@git.vlv-s.site:hhu67/my.git"
|
||||||
["berg"]="ssh://git@codeberg.org/hhu67/my.git"
|
["berg"]="ssh://git@codeberg.org/hhu67/my.git"
|
||||||
["gitea.org"]="git@gitea.com:hhu67/my.git"
|
["gitea.org"]="git@gitea.com:hhu67/my.git"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
3
go/.gitignore
vendored
3
go/.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
.vscode
|
.vscode
|
||||||
.env
|
.env
|
||||||
.*.go.swp
|
.*.go.swp
|
||||||
|
*.so
|
||||||
15
go/README.md
15
go/README.md
|
|
@ -22,4 +22,17 @@ sort:
|
||||||
.SearchТипПеременной(x, 1) - для нахождения индекса числа в срезе
|
.SearchТипПеременной(x, 1) - для нахождения индекса числа в срезе
|
||||||
sort.Sort(sort.Reverse(sort.ТипПеременной(x))) - для сортировки по убыванию
|
sort.Sort(sort.Reverse(sort.ТипПеременной(x))) - для сортировки по убыванию
|
||||||
reflect:
|
reflect:
|
||||||
reflect.DeepEqual(x1, x2) - для сравнения срезов
|
reflect.DeepEqual(x1, x2) - для сравнения срезов
|
||||||
|
os:
|
||||||
|
.Exit(0/1) - для принудительного завершения программы
|
||||||
|
.ReadFile(x.json) - для получения того что находится в файле x.json
|
||||||
|
map:
|
||||||
|
map[ТипКлюча]ТипЗначения{} - для объчвления map
|
||||||
|
delete(x, "Ключ") - для удаления элемента из map
|
||||||
|
x1[x2] = x3 - для добавления элемента в map
|
||||||
|
value, ok := x1[x2] - для проверки существования элемнта в map, ok = true/false, value = значению x1[x2]
|
||||||
|
encoding/json:
|
||||||
|
.Unmarshal(x1, &x2) - для записи в x2 информации формата json, той сырой информации из x1, теперь можно обращаться к ней по x2.ИмяИзСтруктуры
|
||||||
|
github.com/joho/godotenv:
|
||||||
|
godotenv.Load() - для инита .env файла
|
||||||
|
os.Getenv("api") - для записи в переменную значения из env файла с ключом api
|
||||||
26
go/l12.go
Normal file
26
go/l12.go
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
mape := map[int]string{
|
||||||
|
1: "sergey",
|
||||||
|
2: "sergay",
|
||||||
|
}
|
||||||
|
fmt.Println("Введите свое имя")
|
||||||
|
var pol string
|
||||||
|
fmt.Scanln(&pol)
|
||||||
|
mape[len(mape)+1] = pol
|
||||||
|
fmt.Println("Ваше имя:",mape[len(mape)])
|
||||||
|
fmt.Println("Введите число значение каторого хотите увидеть")
|
||||||
|
var i int
|
||||||
|
fmt.Scan(&i)
|
||||||
|
value, ok := mape[i]
|
||||||
|
if ok {
|
||||||
|
fmt.Println(value)
|
||||||
|
} else {
|
||||||
|
fmt.Println("значение",i,"не найдено, значение поиска:",ok)
|
||||||
|
}
|
||||||
|
}
|
||||||
29
go/l13.go
Normal file
29
go/l13.go
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Json struct{
|
||||||
|
Name string `json:"name"`
|
||||||
|
Version int `json:"ver"`
|
||||||
|
Active bool `json:"act"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
jsonn, err := os.ReadFile("l13.json")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Ошибка при чтении файла: %v", err)
|
||||||
|
}
|
||||||
|
var conf Json
|
||||||
|
err = json.Unmarshal(jsonn, &conf)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Ошибка при чтении файла: %v", err)
|
||||||
|
}
|
||||||
|
if conf.Active {
|
||||||
|
fmt.Println("Статус:", conf.Active)
|
||||||
|
}
|
||||||
|
}
|
||||||
5
go/l13.json
Normal file
5
go/l13.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"name": "program",
|
||||||
|
"age": 2288,
|
||||||
|
"act": true
|
||||||
|
}
|
||||||
44
go/l14.go
Normal file
44
go/l14.go
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IPR struct{
|
||||||
|
IP string `json:"origin"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
err := godotenv.Load()
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
proxy := os.Getenv("proxy")
|
||||||
|
proxyURL, err := url.Parse(proxy)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
tran := &http.Transport{
|
||||||
|
Proxy: http.ProxyURL(proxyURL),
|
||||||
|
}
|
||||||
|
myclient := &http.Client {
|
||||||
|
Transport: tran,
|
||||||
|
}
|
||||||
|
url, err := myclient.Get("https://httpbin.org/ip")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
defer url.Body.Close()
|
||||||
|
var ipresp IPR
|
||||||
|
err = json.NewDecoder(url.Body).Decode(&ipresp)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
fmt.Println(ipresp.IP)
|
||||||
|
}
|
||||||
78
go/l15.go
Normal file
78
go/l15.go
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
"os"
|
||||||
|
"net/url"
|
||||||
|
"crypto/tls"
|
||||||
|
)
|
||||||
|
type MyIpData struct{
|
||||||
|
YourIP string `json:"query"`
|
||||||
|
City string `json:"city"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
ISP string `json:"isp"`
|
||||||
|
}
|
||||||
|
type UA struct{
|
||||||
|
UserAgent string `json:"user-agent"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func proxy() (bool, string) {
|
||||||
|
err := godotenv.Load()
|
||||||
|
if err != nil {
|
||||||
|
return false, ""
|
||||||
|
}
|
||||||
|
proxy := os.Getenv("proxy")
|
||||||
|
if proxy == "" {
|
||||||
|
return false, ""
|
||||||
|
}
|
||||||
|
return true, proxy
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
transport := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
|
}
|
||||||
|
er, proxis := proxy()
|
||||||
|
if er {
|
||||||
|
proxyURL, err := url.Parse(proxis)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
transport.Proxy = http.ProxyURL(proxyURL)
|
||||||
|
}
|
||||||
|
fmt.Println("Введите какой хотите user-agent")
|
||||||
|
var polz string
|
||||||
|
fmt.Scanln(&polz)
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: 20 * time.Second,
|
||||||
|
Transport: transport,
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("GET", "https://httpbin.org/user-agent", nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
req.Header.Set("User-Agent", polz)
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
req2, err := http.NewRequest("GET", "http://ip-api.com/json", nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
resp2, err := client.Do(req2)
|
||||||
|
defer resp.Body.Close()
|
||||||
|
var file UA
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&file)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
var data MyIpData
|
||||||
|
err = json.NewDecoder(resp2.Body).Decode(&data)
|
||||||
|
fmt.Printf("Ваш IP: %s\nВаш город по IP: %s\nВаша страна по IP: %s\nВаш провайдер по IP: %s\nВаш User-Agent: %s\n", data.YourIP, data.City, data.Country, data.ISP, file.UserAgent)
|
||||||
|
}
|
||||||
30
go/l16.go
Normal file
30
go/l16.go
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"net/http"
|
||||||
|
"log"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func handler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
err := godotenv.Load()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
PathFile := os.Getenv("html_file_for_l16.go") // Enter the file path for the html_file_for_l16.go variable into the env file
|
||||||
|
html, err := os.ReadFile(PathFile)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(w, string(html))
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/", handler)
|
||||||
|
err := http.ListenAndServe(":2345", nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%v\n", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
5
go/l4.go
5
go/l4.go
|
|
@ -5,13 +5,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func logic() string {
|
func logic() string {
|
||||||
|
var phrase string
|
||||||
fmt.Println("Твой возраст")
|
fmt.Println("Твой возраст")
|
||||||
var x int
|
var x int
|
||||||
_, err := fmt.Scan(&x)
|
_, err := fmt.Scan(&x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "еблан"
|
phrase = "еблан"
|
||||||
|
return phrase
|
||||||
}
|
}
|
||||||
var phrase string
|
|
||||||
switch {
|
switch {
|
||||||
case x < 0:
|
case x < 0:
|
||||||
phrase = "Ты еще не родился"
|
phrase = "Ты еще не родился"
|
||||||
|
|
|
||||||
3
go/l5.go
3
go/l5.go
|
|
@ -4,12 +4,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("не")
|
log.Fatalln(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
api := os.Getenv("api_key")
|
api := os.Getenv("api_key")
|
||||||
|
|
|
||||||
BIN
go/output/l12
Executable file
BIN
go/output/l12
Executable file
Binary file not shown.
BIN
go/output/l13
Executable file
BIN
go/output/l13
Executable file
Binary file not shown.
BIN
go/output/l14
Executable file
BIN
go/output/l14
Executable file
Binary file not shown.
BIN
go/output/l15
Executable file
BIN
go/output/l15
Executable file
Binary file not shown.
BIN
go/output/l16
Executable file
BIN
go/output/l16
Executable file
Binary file not shown.
BIN
go/output/l4
BIN
go/output/l4
Binary file not shown.
BIN
go/output/l5
BIN
go/output/l5
Binary file not shown.
Loading…
Reference in a new issue