[go-nuts] Returning empty string in chi.URLParam function

2022-02-17 Thread Денис Мухортов
Idk why its working like that, but if using r.Url.Query().Get("smthg") 
works fine
https://play.golang.com/p/pJ_CZyR8NT-
https://play.golang.com/p/ixuHln2JirB

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ac66818c-a1bf-4627-9320-7ffb84ea5348n%40googlegroups.com.


[go-nuts] Q about defer

2021-12-24 Thread Денис Мухортов
https://play.golang.com/p/lypWMc6Kuff
Why do we get 2 in test() and 1 in anotherTest()? Is it related to the 
definition of the variable in the output? 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/420ec52b-8243-4b25-ad40-08a16b228a2dn%40googlegroups.com.


[go-nuts] question about stdin

2021-12-12 Thread Денис Мухортов
It's a little unclear how os.stdin actually works. Why, if you just run the 
program, is data from stdin constantly being listened to? 
For example:
func main() {
sc := bufio.NewScanner(os.Stdin)
for sc.Scan() {
txt := sc.Text()
fmt.Printf("echo: %s\n", txt)
}
} But if you send it to stdin ahead of time, the loop will run once and the 
program will exit(echo smth | go run main.go) 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/268474da-8748-482a-b961-f50fcdbcd68dn%40googlegroups.com.


[go-nuts] From interface to []rune

2021-12-08 Thread Денис Мухортов
Can i get data from interface to []rune like that:
https://play.golang.com/p/XpXTeUgL-Tn
If so, how??

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/92755612-a157-4cc8-b6f5-fe65610ee1d7n%40googlegroups.com.


[go-nuts] Whats wrong with my builder pattern

2021-12-05 Thread Денис Мухортов
I have 2 empty strings in the output. But why?
https://play.golang.com/p/v7zEVBM17YH

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4060a981-f43c-49ec-92f7-849ab23d1ea9n%40googlegroups.com.


[go-nuts] nil

2021-12-02 Thread Денис Мухортов
How can the output of the program be explained? Why checking for nil gives 
false??
https://go.dev/play/p/9O1nNgCHg2c

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3861e221-e534-4b30-a3bd-09c9cf8a27abn%40googlegroups.com.


[go-nuts] Goroutines and mutex

2021-11-28 Thread Денис Мухортов
Why are the values not incremented when declaring a structure with mutex in 
goroutines?
https://go.dev/play/p/bPc1bg0AvJ4

And what is the actual point in declaring something in anonymous functions, 
if in my experience it always works without it?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7f3aaf03-0705-4e19-b027-68764b185b4dn%40googlegroups.com.


[go-nuts] Why IF might not work

2021-11-23 Thread Денис Мухортов
I want to collect subsets of numbers in increments of 10. All numbers pass 
if correctly, except 32.5. The result of its division is 1.625. But for 
some reason it passes if twice, I added different numbers, all work 
correctly
https://go.dev/play/p/kdJu-PBsbpC

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/07dcc809-6d21-4e60-9a0e-95514719bb4en%40googlegroups.com.


[go-nuts] Nested structure

2021-11-15 Thread Денис Мухортов
Hello everyone, there is a small problem how to get the total price field 
from the Order structure?
type Order struct {
OrderUID  string  `json:"order_uid"`
Entry string  `json:"entry"`
InternalSignature string  `json:"internal_signature"`
Payment   Payment `json:"payment"`
Items []Items `json:"items"`
Localestring  `json:"locale"`
CustomerIDstring  `json:"customer_id"`
TrackNumber   string  `json:"track_number"`
DeliveryService   string  `json:"delivery_service"`
Shardkey  string  `json:"shardkey"`
SmID  int `json:"sm_id"`
} 
type Items struct {
ChrtID int`json:"chrt_id"`
Price  int`json:"price"`
Ridstring `json:"rid"`
Name   string `json:"name"`
Sale   int`json:"sale"`
Size   string `json:"size"`
TotalPrice int`json:"total_price"`
NmID   int`json:"nm_id"`
Brand  string `json:"brand"`
}
Haven't seen yet that the type of nested structure is a slice 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/91afac2e-7e46-44c0-85ca-550294be2be6n%40googlegroups.com.


[go-nuts] Overwriting cookies when redirecting

2021-11-10 Thread Денис Мухортов
Hello everyone I have a difficulty with cookies.
I am receiving a request from js with json. I get cookie data from the 
body. 
At the same time, I have a redirect to a page where cookies are already 
used. 
Because of this, the data does not have time to register. 
My question is, how do I synchronize this moment so that the redirect 
happens after the cookie is processed? 
Where in general is it better to do this on js or on go?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/c2056373-5c92-4da8-99d9-b9fdcfe15083n%40googlegroups.com.


[go-nuts] Executing templates

2021-10-26 Thread Денис Мухортов
  I can't include templates in html. A strange thing happens for me: 
when viewing in devtools, I see that everything is parsed first except the 
template,
and then the template itself. Although it is included in the tag in the 
middle of the file. Most likely, this is due to the fact that I wrote this 
in go:

tmp := template.Must(template.ParseFiles(files...))
stone Shop := stones()
err = temp.Execute(w, block)
if err != nil {
log.Fatal(error)
}
err = temp.ExecuteTemplate(w, "stone", stoneShop)
if err != nil {
log.Print(err)
}

I need to transfer different data (block, stoneShop) to one page, and 
stoneShop is used in the template. Perhaps because of the double Execute 
call, such an oddity occurs. How can this be implemented at all, if not so? 
If you need more information, then my git: 
https://github.com/MukhortovDenis/goproject/tree/liltest , where are the 
functions in handlers.go

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20c0b101-26af-4858-bc94-6b713919a1b8n%40googlegroups.com.


Re: [go-nuts] templates in html

2021-10-26 Thread Денис Мухортов
Thanks

вт, 26 окт. 2021 г. в 18:32, Marcin Romaszewicz :

> Have a look at this:
> https://pkg.go.dev/html/template#Template.Funcs
>
> You need to provide a map of function names to function references to the
> template engine, otherwise, it has no idea what "stoneShop" is, because all
> it sees is an interface{} and has no context to know that it's a function.
> This data argument is explored via reflection, so if you reference
> ".Something", the template engine will look in data for a field with that
> name.
>
> The function map that I linked above is where you would provide your
> "stoneShop" function.
>
> On Tue, Oct 26, 2021 at 12:23 AM Денис Мухортов 
> wrote:
>
>> I need to pass data from the map[string]interface{} through the template
>> I dont know why, but I catch the error:
>> template: stone-card.html:2: function "stoneShop" not defined.
>> Code in go:
>> files := []string{
>> dirWithHTML + "index.html",
>> dirWithHTML + "stone-card.html",
>> }
>> tmp, err := template.ParseFiles(files...)
>> if err != nil {
>> fmt.Println(err)
>> }
>> err = tmp.Execute(w, block)
>> if err != nil {
>> log.Fatal(err)
>> }
>> stoneShop := stones()
>> err = tmp.ExecuteTemplate(w, "stone", stoneShop)
>> // var stoneShop map[string]interface{}
>> if err != nil {
>> log.Print(err)
>> }
>> Template Code:
>> {{define "stone"}}
>> {{range $key, $value := stoneShop}}
>> 
>> 
>>   
>> 
>> 
>>   
>> {{$value.Name}}
>>   
>>   
>> {{$value.Description}}
>>   
>>   
>> {{$value.Rare}}
>>   
>>   
>> Купить
>> {{$value.Price}} C
>>   
>> 
>> 
>> {{end}}
>> {{end}}
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/2edfe28a-d136-43a4-819e-081644d1683cn%40googlegroups.com
>> <https://groups.google.com/d/msgid/golang-nuts/2edfe28a-d136-43a4-819e-081644d1683cn%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CA%2Bs54Ca0V8vPS8iLdGyF9i472-W9%3DgatLVV9tg7AG9LLWzuK9w%40mail.gmail.com.


[go-nuts] templates in html

2021-10-26 Thread Денис Мухортов
I need to pass data from the map[string]interface{} through the template
I dont know why, but I catch the error:
template: stone-card.html:2: function "stoneShop" not defined.
Code in go:
files := []string{
dirWithHTML + "index.html",
dirWithHTML + "stone-card.html",
}
tmp, err := template.ParseFiles(files...)
if err != nil {
fmt.Println(err)
}
err = tmp.Execute(w, block)
if err != nil {
log.Fatal(err)
}
stoneShop := stones()
err = tmp.ExecuteTemplate(w, "stone", stoneShop)
// var stoneShop map[string]interface{}
if err != nil {
log.Print(err)
}
Template Code:
{{define "stone"}}
{{range $key, $value := stoneShop}}


  


  
{{$value.Name}}
  
  
{{$value.Description}}
  
  
{{$value.Rare}}
  
  
Купить
{{$value.Price}} C
  


{{end}}
{{end}}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2edfe28a-d136-43a4-819e-081644d1683cn%40googlegroups.com.


[go-nuts] Re: Clearing sessions

2021-10-14 Thread Денис Мухортов
Answering the first one, my server panics with the error: secure cookie: 
the value is invalid. 
The error occurs if I restart the server and the session is saved in the 
browser. 
For me, it's enough just to delete this value from the browser so that the 
server starts without panic, 
but I would like to do it normally.
Answering the second, I have CI/CD, which is easier to work with, but 
gitignore will not allow the application to connect to the database 
immediately on the hosting.
I would like the code to be public and CI/CD to work without problems

четверг, 14 октября 2021 г. в 10:14:08 UTC+3, Brian Candler: 

> 1. If you are getting a panic, then you should show the complete error 
> message together with the backtrace, and it will help someone diagnose 
> what's going on.  I don't think that simply having stale sessions in your 
> cookie store should cause your program to crash.  Indeed, that's one of the 
> benefits of having a persistent cookie store: it should allow your 
> application to be restarted and users' existing sessions should continue 
> unaffected.
>
> 2. Do you realise that you've just given the entire world the credentials 
> to access your database?
>
> https://github.com/MukhortovDenis/goproject/blob/main/cmd/web/handlers.go#L22
>
> You should keep secrets out of your source code.  If your hosting setup 
> lets you pass environment variables to your application at runtime, that 
> would be an easy way to fix it: use os.Getenv() 
> .  Or put the secret into a 
> separate file that you read when the application starts, but you don't 
> commit to version control (use ".gitignore" to prevent it being added by 
> accident).  Or pass it as a command-line argument.
>
> This is good practice even if the source code were kept private.  Passing 
> configuration to your application lets the same code be used in dev, test 
> and production environments.
>
> On Thursday, 14 October 2021 at 06:34:54 UTC+1 muhorto...@gmail.com wrote:
>
>>  Hi, there! How to properly clean up sessions after before disconnecting 
>> the server or before starting it?  have a problem that the server
>> is on a free hosting that periodically shuts down the server. 
>> Since cookies are stored with me and they are no longer relevant,
>> my server is panicking. This is also necessary for local testing.
>>  What to do and what to use in such cases?
>> https://github.com/MukhortovDenis/goproject
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/238ae479-21b1-438b-ac02-3a1ab1b4ae1dn%40googlegroups.com.


[go-nuts] Clearing sessions

2021-10-13 Thread Денис Мухортов
 Hi, there! How to properly clean up sessions after before disconnecting 
the server or before starting it?  have a problem that the server
is on a free hosting that periodically shuts down the server. 
Since cookies are stored with me and they are no longer relevant,
my server is panicking. This is also necessary for local testing.
 What to do and what to use in such cases?
https://github.com/MukhortovDenis/goproject

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5143e897-d1a8-4d62-955d-d3b2b2defcdan%40googlegroups.com.


[go-nuts] Logging in to web services

2021-10-12 Thread Денис Мухортов
Hi, I have a question that is difficult for me to describe, but at the 
level of fundamental questions about creating a web service. I have a 
problem that if a user logs into a profile, then another user will also get 
into his profile. Generally speaking, this is the property of any person 
who visits the site. I see a solution to the problem in two ways. I do not 
know if it is possible to somehow track connections and give each IP its 
own routine in which it worked. Or dynamic pages that can only be accessed 
if the request is successful. But again, some data in the structures may 
change due to another user logged into the profile. Maybe there is some 
other solution to this problem. I want to understand how it works on the 
web.
My project just in case: https://github.com/MukhortovDenis/goproject

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4ad11bd0-fe99-4d86-b70d-be09b48ae638n%40googlegroups.com.


[go-nuts] Trouble with pgx package

2021-10-02 Thread Денис Мухортов
Just started making my first web, I don't quite understand the Query Row 
function. An error is returned, I process it. What is the error?
func save(w http.ResponseWriter, r *http.Request) {
login := r.FormValue("login")
password := r.FormValue("password")
if login == "" || password == "" {
fmt.Fprint(w, "Не все данные введены")
}
conn, err := pgx.Connect(context.Background(), connStr)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
err := conn.QueryRow(context.Background(), "INSERT INTO users (login, 
password) VALUES ($1, $2)", login, password)
if err != nil {
return err
}
defer conn.Close(context.Background())
http.Redirect(w, r, "/", http.StatusSeeOther)
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/4e9d2371-d601-423e-b478-4d83a3d7d3d4n%40googlegroups.com.


[go-nuts] Whats wrong with my channel

2021-08-19 Thread Денис Мухортов
I just started practicing with channels, after writing to the channel, 
nothing is output from there
func main() {
d := make(chan int)
go factorial(5, d)
 time.Sleep(3 * time.Second)
}

func factorial(n int, d chan int) {
fmt.Println("function starting...")
time.Sleep(3 * time.Second)
var a int = 1
for ; n > 0; n-- {
a *= n
}
d <- a // //nothing works after that
fmt.Println(<-d)
fmt.Println(a)
}

Another question I want to make a recursive function with a factorial, pass 
it to goroutine in main. But I do not know if it is possible to somehow 
combine *return* and a channel in the declaration of arguments.
-
if I first pass in something to the channel from main,
a lock occurs.Why? So it's not possible at all?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f7527636-00e0-42d1-84f4-7aebcf12c984n%40googlegroups.com.


[go-nuts] Working with interfaces

2021-08-14 Thread Денис Мухортов
I started studying interfaces, tried to write them in different ways, but I 
don't understand what I'm doing wrong. In the first case, everything works, 
but I don't understand why it doesn't work in the second
FIRST
package main

import (
"fmt"
"math"
)

type Circle struct {
r int
}
type Rectangle struct {
a int
b int
}
type operations interface {
Area() int
}

func (r Rectangle) Area() int {
s := r.a * r.b
return int(s)
}
func (c Circle) Area() int {
s := math.Pi * math.Pow(float64(c.r), 2)
return int(s)

}
func printArea(o operations) {
fmt.Print(o.Area(), " ")
}
func main() {
circle := Circle{5}
rectangle := Rectangle{4, 5}
printArea(circle)
printArea(rectangle)
}

SECOND
package main

import (
"fmt"
"math"
)

type Circle struct {
r int
}
type Rectangle struct {
a int
b int
}
type operations interface {
Area() int
}

func (r Rectangle) Area() int {
s := r.a * r.b
return int(s)
}
func (c Circle) Area() int {
s := math.Pi * math.Pow(float64(c.r), 2)
return int(s)

}

func main() {
var o operations
circle := Circle{5}
rectangle := Rectangle{4, 5}
squareCirc := o.Area(circle)
squareRect := o.Area(rectangle)
fmt.Print(squareCirc, squareRect)
}


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f845b2a9-2b1b-4ef9-a7cb-2a86e76f6869n%40googlegroups.com.


[go-nuts] Convert json to css for golang

2021-06-19 Thread Денис Мухортов
Hi everyone, I need a converter from json to css.I use 
https://github.com/ysugimoto, it translates css to json, then I connect 
some plugins that change the json, and after that I need to recreate it 
back to css. Do not advise Postcss because I'm just trying to make it 
similar to Golang

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ad18bfd9-5b40-4aaa-97a8-d304e3d4cf0fn%40googlegroups.com.


[go-nuts] PostCSS clone for golang

2021-06-11 Thread Денис Мухортов
I'm just getting into the PostCSS topic, and I'm wondering how up-to-date 
the gssp clone is (https://github.com/ysugimoto/gssp). As I understand it, 
there is no generator that collects structures back to css, is there? And 
if you can use it, how to connect modules from PostCSS?
*Thank you in advance!*

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2680f2f7-4ab1-4d5e-bcd7-f82f91192a6fn%40googlegroups.com.


[go-nuts] What are the analogues of PostCSS for go

2021-05-27 Thread Денис Мухортов
I would like to consider several alternatives. Pros and cons of each of 
them. Thank you in advance)

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/04278621-a346-405a-b454-f1259d498012n%40googlegroups.com.


[go-nuts] problem with starting to use pug/jade

2021-05-07 Thread Денис Мухортов
I started using the library https://github.com/Joker/jade, never used go 
generate before. And now when trying to create hello.jade, I get the output 
' "jade": exec: "jade": executable file not found in %PATH%'.
Does this mean that I need to specify pug in the global variables, or do I 
need to do something in the library itself

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7b8f997c-d950-4965-8d2b-03b1fa05c9edn%40googlegroups.com.


[go-nuts] Pug-->Html. I need the lib fot this

2021-05-05 Thread Денис Мухортов
Does anyone know a lib that precomlies from pug to html?Interested in 
something other than https://github.com/Joker/jade, well, or explain how to 
use this lib specifically??

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/879bd67a-dc39-44a5-b58a-e3f33f4caf06n%40googlegroups.com.