Compare commits
No commits in common. "088fa647f55f3c02b00d0c51d070b0045ace385d" and "7c5926b97a69d869331809d1083b17a79bdabeb2" have entirely different histories.
088fa647f5
...
7c5926b97a
18 changed files with 6 additions and 234 deletions
2
git.sh
2
git.sh
|
|
@ -7,7 +7,7 @@ git commit -m "$com"
|
|||
declare -A remotes=(
|
||||
["gitflic"]="git@gitflic.ru:hhu67/proj.git"
|
||||
["github"]="git@github.com:hhu67/my.git"
|
||||
["forgejo"]="forgejo@git.vlv-s.site:hhu67/my.git"
|
||||
["forgejo"]="git@git.vlv-s.site:hhu67/my.git"
|
||||
["berg"]="ssh://git@codeberg.org/hhu67/my.git"
|
||||
["gitea.org"]="git@gitea.com:hhu67/my.git"
|
||||
)
|
||||
|
|
|
|||
3
go/.gitignore
vendored
3
go/.gitignore
vendored
|
|
@ -1,4 +1,3 @@
|
|||
.vscode
|
||||
.env
|
||||
.*.go.swp
|
||||
*.so
|
||||
.*.go.swp
|
||||
15
go/README.md
15
go/README.md
|
|
@ -22,17 +22,4 @@ sort:
|
|||
.SearchТипПеременной(x, 1) - для нахождения индекса числа в срезе
|
||||
sort.Sort(sort.Reverse(sort.ТипПеременной(x))) - для сортировки по убыванию
|
||||
reflect:
|
||||
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
|
||||
reflect.DeepEqual(x1, x2) - для сравнения срезов
|
||||
26
go/l12.go
26
go/l12.go
|
|
@ -1,26 +0,0 @@
|
|||
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
29
go/l13.go
|
|
@ -1,29 +0,0 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"name": "program",
|
||||
"age": 2288,
|
||||
"act": true
|
||||
}
|
||||
44
go/l14.go
44
go/l14.go
|
|
@ -1,44 +0,0 @@
|
|||
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
78
go/l15.go
|
|
@ -1,78 +0,0 @@
|
|||
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
30
go/l16.go
|
|
@ -1,30 +0,0 @@
|
|||
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,14 +5,13 @@ import (
|
|||
)
|
||||
|
||||
func logic() string {
|
||||
var phrase string
|
||||
fmt.Println("Твой возраст")
|
||||
var x int
|
||||
_, err := fmt.Scan(&x)
|
||||
if err != nil {
|
||||
phrase = "еблан"
|
||||
return phrase
|
||||
return "еблан"
|
||||
}
|
||||
var phrase string
|
||||
switch {
|
||||
case x < 0:
|
||||
phrase = "Ты еще не родился"
|
||||
|
|
|
|||
3
go/l5.go
3
go/l5.go
|
|
@ -4,13 +4,12 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"github.com/joho/godotenv"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
fmt.Println("не")
|
||||
return
|
||||
}
|
||||
api := os.Getenv("api_key")
|
||||
|
|
|
|||
BIN
go/output/l12
BIN
go/output/l12
Binary file not shown.
BIN
go/output/l13
BIN
go/output/l13
Binary file not shown.
BIN
go/output/l14
BIN
go/output/l14
Binary file not shown.
BIN
go/output/l15
BIN
go/output/l15
Binary file not shown.
BIN
go/output/l16
BIN
go/output/l16
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