Re: [go-nuts] UML && Golang, part 2 ?

2021-07-05 Thread Vladimir Varankin
For the current system, that concists of <100 µ-services (the whole system 
is owned by one team), I'm trying to evaluate C4 model https://c4model.com. 
TBF, this is an ongoing experiment for myself, and I don't try to strictly 
follow the C4's nomenclature, but I find the idea of zooming-in & 
zooming-out from the system to answer different questions in different 
contexts, appeling.

I belive, UML defines of a bunch of diagram types (both structural and 
behavioral) — I don't think it's fair to ask, what one uses instead. It all 
depends on the context.

On Monday, July 5, 2021 at 7:13:02 AM UTC+2 xav...@gmail.com wrote:

> Is it true that UML is unpopular? I don't think you'll catch many gophers 
> writing class diagrams, but I've found higher level UML diagrams useful.
>
> That said, I find UML somewhat overspecified for day-to-day use. A simple 
> block diagram is often enough for me to explain something to a coworker or 
> as a piece of supplementary documentation.
>
> On Sun, Jul 4, 2021, 04:16 alex-coder  wrote:
>
>> Ok, folk, as I see UML is not very popular within the community. :-)
>> But what do you use instead then ?
>>
>> Anyway it must be some tool to present the code as a picture.
>> The picture is worth a thousand words :-).
>>
>> Thank you.
>>
>> -- 
>> 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...@googlegroups.com.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/db5362fb-6365-4b88-9b56-98c88cd5cb62n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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/28e301bf-ac19-49c1-b558-2b346cd015can%40googlegroups.com.


[go-nuts] Re: question about Profiling Go Programs sample.

2021-09-27 Thread Vladimir Varankin
Hello,

I suspect this is due to how the current version of Go runtime's CPU 
profiler keeps only up to 64 items, when it builds the function's stack 
frame (refer to 
https://github.com/golang/go/blob/go1.17/src/runtime/cpuprof.go#L21) With 
that, the resulting profile misses the relationship between main.DFS and 
its parent function, thus it "hangs" beneath the root node now.

Keep in mind that the original post is almost 10 year old now. Some other 
details might have changed as well.

Cheers,
V.

On Monday, September 27, 2021 at 11:03:53 AM UTC+2 alex-coder wrote:

> Hi All,
>
> currently I walk through sample given there:
> Profiling Go Programs - go.dev 
>
> but when I came at the point where the user should enter web command to 
> the pprof
> I do not see that the function DFS call itself on a picture.
> Looks like I do use a proper version of the sample - go_pro, where the 
> recursion is present:
> multi-language-bench/src/havlak/go_pro at master · 
> hundt98847/multi-language-bench · GitHub 
> 
>
> So, what could be the reason that the picture is painted not properly ?
>
> I use 1.17.1, windows 10.
>
> Thank you.
>
>

-- 
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/638c15d8-7dd4-4db4-9be5-7fdc80da00b6n%40googlegroups.com.


[go-nuts] Re: question about Profiling Go Programs sample.

2021-09-29 Thread Vladimir Varankin
Hey there,

> I took  runtime/cpuprof.go with  version 1.4, where cpuprof.go just 
appeared with the same result. :-)

I think this is expected.
Go 1.4 was released in 2014 — several years after the original post about 
pprof, had been published. In fact, Go 1.4 is the version where the 
relevant part of the runtime's profiler was migrated from C to Go. In this 
version the same constant, I pointed earlier, already presented in this 
source code (note maxCPUProfStack=64).

> Vladimir, is there any resource to read about current and probably future 
of the go profiling?

Depending on what you're looking for, there are quite a few materials I 
could recommend:
- the documentation for runtime/pprof and net/http/pprof packages [1]
- the documentation for google/pprof tool [2]
- Go wiki on performance [3]
- Felix Geisendörfer's (DataDog) notes on Go profiling internals [4] (he 
also gave several talks about the topic last summer).

Hope that could help.

[1]: https://pkg.go.dev/runtime/pprof, https://pkg.go.dev/net/http/pprof
[2]: https://github.com/google/pprof/tree/master/doc
[3]: https://github.com/golang/go/wiki/Performance
[4]: https://github.com/DataDog/go-profiler-notes
On Wednesday, September 29, 2021 at 1:59:10 PM UTC+2 alex-coder wrote:

> Vladimir,
>
> I took  runtime 
>  
> /
> cpuprof.go 
>  
> with  version 
> 1.4, where cpuprof.go just appeared with the same result. :-)
> it should be something else.
>
> Regards.
>
> вторник, 28 сентября 2021 г. в 11:31:55 UTC+3, alex-coder: 
>
>> Ok, thank you.
>> Vladimir, is there any resource to read about current and probably future 
>> of the go profiling ?
>> In fact it is not only very important but and very, very interesting.
>>
>> Thank you.
>>
>>
>> вторник, 28 сентября 2021 г. в 06:38:31 UTC+3, vlad...@varank.in: 
>>
>>> Hello,
>>>
>>> I suspect this is due to how the current version of Go runtime's CPU 
>>> profiler keeps only up to 64 items, when it builds the function's stack 
>>> frame (refer to 
>>> https://github.com/golang/go/blob/go1.17/src/runtime/cpuprof.go#L21) 
>>> With that, the resulting profile misses the relationship between main.DFS 
>>> and its parent function, thus it "hangs" beneath the root node now.
>>>
>>> Keep in mind that the original post is almost 10 year old now. Some 
>>> other details might have changed as well.
>>>
>>> Cheers,
>>> V.
>>>
>>> On Monday, September 27, 2021 at 11:03:53 AM UTC+2 alex-coder wrote:
>>>
 Hi All,

 currently I walk through sample given there:
 Profiling Go Programs - go.dev 

 but when I came at the point where the user should enter web command to 
 the pprof
 I do not see that the function DFS call itself on a picture.
 Looks like I do use a proper version of the sample - go_pro, where the 
 recursion is present:
 multi-language-bench/src/havlak/go_pro at master · 
 hundt98847/multi-language-bench · GitHub 
 

 So, what could be the reason that the picture is painted not properly ?

 I use 1.17.1, windows 10.

 Thank you.



-- 
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/cbb10024-3da0-474d-a3f5-a43df3b99427n%40googlegroups.com.


[go-nuts] Re: Practical use cases of recover in golang

2022-10-10 Thread Vladimir Varankin
One particular example is if you use std's net/http server, you 
(indirectly) use recover. The std's documentation for the Handler interface 
has a section, where they outline how the server recovers from a panic, 
that fired in the context of a request https://pkg.go.dev/net/http#Handler

On Sunday, October 9, 2022 at 11:16:52 PM UTC+2 cg-guy wrote:

> Hi Team,
>
> Whatever I have been worked so far with golang,I did not use recover() 
> function . 
> Curious to know if anyone using recover in production code and can you 
> please 
> the scenarios where it is used. 
>
> Thanks
>

-- 
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/da146c8e-2275-4163-b43e-879f52d139d8n%40googlegroups.com.


[go-nuts] Re: What happened if http timeout happened but the request is still sent out

2023-01-04 Thread Vladimir Varankin
> If the connection to the server is lost while transmission, you will 
probably receive a broken pipe error.
> If the timeout happens before sending data, nothing to care.
> If the timeout happens during data transmission, well, you may have 
incomplete data(corrupted) in the server.

In addition to the cases above, there may be a situation when the server 
received the request fully, but didn't send the response back yet, and the 
client has dropped (e.g. timeouted).
I don't think there is "a correct" behaviour for that on the HTTP side. The 
application's parties (both client and server) must agree on their own 
rules for handling (or ignoring) such cases.

On Wednesday, January 4, 2023 at 11:02:49 AM UTC+1 w54n wrote:

> If the connection to the server is lost while transmission, you will 
> probably receive a broken pipe error.
> If the timeout happens before sending data, nothing to care.
> If the timeout happens during data transmission, well, you may have 
> incomplete data(corrupted) in the server.
>
> I don't think there is any way to prevent such thing in the std library 
> itself. Your server must be capable to handle state properly, validate what 
> it is receiving and decide if it should keep it or not, thus, yes, this is 
> all application layer logic.
>
> I think this all relates to how your server will treat idempotence and 
> atomic writes. 
>
> On Tuesday, January 3, 2023 at 8:10:03 AM UTC+1 xieyu...@gmail.com wrote:
>
>> Hi, recently I wondered the question about what would happen if http 
>> timeout but the request is still sent out.
>> The motive is, let's assume we make a post request with a timeout. When 
>> timeout, the request is canceled, and the server won't serve it anymore.
>>  However, if the request is sent out when timeout, the server actually 
>> proceeds it anyway, which may make an unexpected error. 
>> So I would like to know how to avoid such an error. Do we need to 
>> additional check in the application layer, or could we check it inside the 
>> http library?
>>
>> I triggered the timeout by debugger breakpoint in goland, I set the 
>> breakpoint at err = pc.bw.Flush() 
>> 
>>  in 
>> writeLoop and n, err = w.pc.conn.Write(p) 
>> 
>> .
>> In my opinion, the socket is closed once the timeout happens, and the  n, 
>> err = w.pc.conn.Write(p) 
>> 
>>  will 
>> always fail as *use of closed network connection*.
>> However, the result is it could send out the bytes, I guess it's caused 
>> by the debugger, but have no idea about it.
>> [image: Image Pasted at 2023-1-3 15-09.png]
>>
>>
>>

-- 
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/cc2e6647-cb17-4561-9897-73e3d97c4733n%40googlegroups.com.


[go-nuts] Re: Debugging memory leak when a GO process crashed

2023-01-13 Thread Vladimir Varankin
Hey Mariappan,

>From my experience, there are several possible options:

I believe you can use GOTRACEBACK=crash env variable (or its equivalent in 
the runtime/debug package in the std) to get a coredump on the crash. See 
this old post from JBD [1], that explored this.

If you clearly observe, that the application "leaks" its memory (or it 
"leaks goroutines") via the metrics — simple by looking at the trends in 
the app's memory usage — you may collect several pprof files (heap and 
goroutines), with some interval. Then explore the diff between the two 
profiles with pprof tool's diff option. To help automating this, the 
continuous profiling became a fairly trendy thing in the recent years. I 
won't recommend the actual project I explained back then in the [3], but 
the overall idea still valid, and there are several big and small offerings 
for that nowadays.

Hope this will help.

[1]: https://rakyll.org/coredumps/
[2]: https://pkg.go.dev/runtime/debug#SetTraceback
[3]: https://medium.com/@tvii/continuous-profiling-and-go-6c0ab4d2504b

On Tuesday, January 10, 2023 at 8:55:18 AM UTC+1 mariappa...@gmail.com 
wrote:

> Hello Go experts,
>
> I could able to find the solution to debug memory leaks of GO process, 
> when it is running by using PPROF. Is it possible to collect the heap 
> profile for debugging, when GO process crashed using core dump? or what is 
> the recommended way to root cause the memory leak? Based on the need, 
> enabling PPROF and debugging may not be possible in the production 
> environment. Please help. 
>
> Best Regards
> Mariappan
>

-- 
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/b33dc147-7099-494c-8a04-e4507d410d8dn%40googlegroups.com.


Re: [go-nuts] Re: Looking for a specialized proxy package

2023-03-16 Thread Vladimir Varankin
Hey Michael,

> The piece I'm missing is how to construct a proxying handler that will 
use the identifier in the link to look up the tunnel port and fetch the 
IOT's home page and thereafter make it seem as though the user is directly 
browsing the IOT.

If I got the question right, there are two parts:

1. Build an HTTP reverse proxy, which routes the requests to a target 
device's server (i.e. the upstream).

Go's httputil.ReverseProxy 
(https://pkg.go.dev/net/http/httputil#ReverseProxy) can do that. You will 
need to implement httputil.ReverseProxy.Rewrite to route a request.

2. Use the identifier in the link to look up the tunnel port 

Not sure, if I've missed what "link" means in this context — is this a 
network interface, the devices are connected to?

On Thursday, March 16, 2023 at 2:17:09 AM UTC+1 Michael Ellis wrote:

> Thanks, Matthew.  I know what RPC is, but have never considered it as a 
> way to serve http from behind a NAT.  I should say that the IOT's are part 
> of a product that's been in the market for several years.  My client likes 
> the web interface we built and wants users to be able to access an IOT's 
> pages through a secure intermediary server.  How would that work with grpc?
>
> On Wednesday, March 15, 2023 at 7:08:04 PM UTC-4 Matthew Zimmerman wrote:
>
>> Honestly I'd probably use grpc and keep a constant connection from the 
>> IOT to the cloud.  No ports/services required on the client at all and the 
>> server can still request things in real time.
>>
>> Like: 
>> https://www.talentica.com/blogs/part-3-building-a-bidirectional-streaming-grpc-service-using-golang/
>>
>> On Wed, Mar 15, 2023, 6:35 PM Michael Ellis  wrote:
>>
>>> FWIW,  I pasted my  post into ChatGPT-4 and got what might be a 
>>> plausible outline of an approach using 
>>> httputil.NewSingleHostReverseProxy.
>>>
>>> But, as we know, LLM's are prone to hallucination. If you're curious, 
>>> here's a share link. 
>>>
>>> https://shareg.pt/cNoNdWc
>>>
>>> On Wednesday, March 15, 2023 at 5:57:48 PM UTC-4 Michael Ellis wrote:
>>>
 I posted a question about this on ServerFault 
 last
  
 week but didn't get any answers other than a few comments from one person 
 who said (basically) "use a VPN".   That seems like overkill.  I'm trying 
 to find a reliable way to proxy occasional HTTP access to any of  ~100 
 geographically dispersed IOT devices through a cloud server.  

 I'm using Go on the cloud server and on the IOT devices, so I thought 
 I'd ask here.

 *Situation:*

- We have complete control over the configuration of the IOT 
devices and the cloud host.
- We don't have control of the customers' routers and firewalls, 
but can specify minimum requirements for port openings, etc.
- FWIW, the IOT devices are BeagleBone Black running Debian Buster 
and the cloud host will be, typically, a multi-core droplet (or 
 similar) 
running Linux.
- The IOT's serve dynamic web pages over HTTP. (HTTPS doesn't seem 
feasible because of certificate requirements and overall load on the 
 IOT 
cpu.) The cloud host will have HTTPS capability.
- This is a low-traffic situation. The IOT's report some overall 
status information (via rsync/ssh) at 4 minute intervals). We already 
 have 
a web interface (written in Go) on the cloud server that aggregates and 
displays the status reports.
- Access to an IOT's web service will only occur when a user wants 
to investigate a problem report in more detail. Typically, only one or 
 two 
users will have credentials to browse the cloud server.

 The scheme I have in mind is: 

1. At configuration time for each IOT device the installation tech 
will use ssh-copy-id to install the IOT device's public key on the 
 cloud 
service.
2. The IOT device will  then remotely execute a one-shot program 
(already written and tested) on the cloud server.  The IOT will provide 
 a 
unique identifier as an argument and the program will return a 
 permanent 
port number and add a record to a database to record the assignment.
3. The IOT will open a reverse SSH tunnel on the server (probably 
managed by auto-ssh) specifying the permanent port on the server and a 
local port on which it will listen for HTTP requests.
4. The cloud server, when generating status report pages, will 
include a link to fetch the home page of each IOT device by embedding 
 its 
unique identifier specified in step 2 above.

 The piece I'm missing is how to construct a proxying handler that will 
 use the identifier in the link to look up the tunnel port and fetch the 
 IOT's home page and thereafter

[go-nuts] Re: Why is the reason that the flame graph in go pprof rotated 180 degrees?

2023-06-14 Thread Vladimir Varankin
Hey there,

In this issue, back then (https://github.com/google/pprof/issues/359), I 
linked my interpretation for the reasoning to switch from flame graph to 
"icicle graph". Just as you wrote, in some (many) cases, the investigations 
starts from the bottom of the graph, forcing a user to scroll down, when 
the graph was higher then their screen height.

On Tuesday, June 13, 2023 at 11:59:38 AM UTC+2 a2800276 wrote:

> 180 degrees in respect to what? ;) 
> I'd argue callgraphs have no "natural" orientation, top to bottom is as 
> good as bottom to top or left to right (right to left feels off to me, but 
> I read left to right, so I assume that's just a matter of familiarity)
>
> On Monday, 12 June 2023 at 14:26:30 UTC+2 fliter wrote:
>
>> Why is the  reason that the flame graph in go pprof rotated 180 degrees?
>>
>> The reason I can think of is that it seems that this conforms to the func 
>> calling order from top to bottom.
>>
>> Thanks for anyone's discussion and replies
>>
>

-- 
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/e6f8d4cc-ded9-46a1-8518-3268d65c387bn%40googlegroups.com.


[go-nuts] Re: Why doesn't the database/sql package in Go support using placeholders "?" to replace the database name and username in SQL statements?

2023-09-18 Thread Vladimir Varankin
A thing, that it may be valuable to explain further, is that Go's 
"database/sql" doesn't come with a built-in query builder. 

The package implements the database connection pooling/management, but it 
passes the user's SQL input and its arguments to the "driver". Depending on 
the particular database kind, the driver may or may not try to interpret 
the query (and the args), before it passes them to the database server.

In the specific example of MySQL/MariaDB, the support for placeholder "?" 
is a part of this database's flavour of SQL. Thus, it's likely, the driver 
you're using, passes the query with a placeholder to the DB server, but the 
DB's support of placeholders is limited to only a subset of queries (or 
places inside a query) — as the link to SO's answer, shared previously, 
explained.

Hope this makes it a little bit more clear.

On Sunday, September 17, 2023 at 10:45:27 AM UTC+2 Brian Candler wrote:

> According to this SO answer, CREATE USER in mysql doesn't support 
> placeholders:
>
> https://stackoverflow.com/questions/20647115/how-to-write-create-user-with-mysql-prepared-statement
> *"+1 for a legitmiate use of QUOTE() which is really the sanest thing that 
> can be done here, since CREATE USER doesn't support ? placeholders"*
>
> You can test this by trying a simple DML statement, e.g.
> UPDATE users SET name=? where name=?
>
> On Sunday, 17 September 2023 at 01:02:08 UTC+1 John Zh wrote:
>
>> Hi !
>> I am going to make some kind of manager app over MySQL clusters by using 
>> Golang. But I found that when I try to exec some SQL line includes user 
>> name or db name, the SQL line can't be correctly parameterized.
>> For example:
>> Using GORM based on database/sql or directly using database/sql
>> ```
>> err := db.Exec("CREATE USER ? IDENTIFIED BY ?", a.Name, a.Pwd).Error
>> ```
>> Got
>> ```
>> [1.824ms] [rows:0] CREATE USER 'Reiis' IDENTIFIED BY '12345'
>> Error 1064 (42000): You have an error in your SQL syntax; check the 
>> manual that corresponds to your MySQL server version for the right syntax 
>> to use near '? IDENTIFIED BY ?' at line 1
>> ```
>>
>> Seems like it does not replace "?" with a.Name, but rather passes the SQL 
>> command with "?" directly to MySQL.  What is more wired, it prints the 
>> SQL command with correctly replaced parameters in the log.
>>
>> I don't know the the underlying reason behind this phenomenon, is it 
>> intentionally designed like that?
>> Thx!
>>
>

-- 
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/1cc07940-48c3-4d53-b97e-d74faa4c76can%40googlegroups.com.


[go-nuts] Re: When net package is imported building binary with CGO generate error

2023-11-03 Thread Vladimir Varankin
Hey there,

Which OS (Linux distro) you're using? As far as I can see from cgo_linix.go 
[1], the constants, that trigger an error, should come from the "netdb.h", 
which comes with libc.

[1]: https://github.com/golang/go/blob/go1.19.13/src/net/cgo_linux.go

On Thursday, November 2, 2023 at 3:21:53 PM UTC+1 sbezverk wrote:

>  
>
>  
>
> Hello,
>
>  
>
> I came across a situation when “net” package is imported regardless 
> directly or indirectly via another package, go build generates these errors:
>
>  
>
> /sw/packages/go/1.19.4/src/net/cgo_linux.go:20:59: could not determine 
> kind of name for C.AI_ALL
>
> /sw/packages/go/1.19.4/src/net/cgo_linux.go:20:43: could not determine 
> kind of name for C.AI_V4MAPPED
>
>  
>
> I could not find any clues on the internet, curious if somebody saw 
> similar issue and somehow has fixed it.
>
>  
>
> Thank you
>
> Serguei
>

-- 
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/31212bb8-011b-410a-a3cd-838c6d439613n%40googlegroups.com.


Re: [go-nuts] Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-13 Thread Vladimir Varankin
> [..] when the method modifies the sruct's members (or just have a 
sync.Mutex member)

>From my experience, these are the major points for defaulting to use the 
pointer receiver "when in doubt". The difference between "func (t T) Foo" 
and "func (t *T) Foo", is often too subtle to spot a bug in a code change 
of a real production project. This is for sure, not the ultimate solution 
for human-errors. But it's pragmatic.

On Tuesday, November 14, 2023 at 6:37:27 AM UTC+1 Tamás Gulácsi wrote:

> I've always try to start with a value receiver,
> change to pointer receiver (EVERYWHERE - do not mix pointer and value 
> receivers!),
> when the method modifies the sruct's members (or just have a sync.Mutex 
> member),
> or used as interface (i.e. error  - for comparison to nil)
>
> Oliver Lowe a következőt írta (2023. november 14., kedd, 0:23:44 UTC+1):
>
>> > I'd be curious to hear thoughts on this topic. 
>>
>> There was a fun talk at GopherConAU just a few days ago: "What's 
>> The Point? A Guide To Using Pointers Without Panicking" (talk 
>> description at https://gophercon.com.au/) When the recordings are 
>> all finalised I can reply to this thread with a link. 
>>
>

-- 
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/38dea6ca-5dc8-4e78-b50d-ca10f00bbaabn%40googlegroups.com.


Re: [go-nuts] Compilation fails when adding option "-trimpath", because change a dependency to require gcc

2020-02-10 Thread Vladimir Varankin
I faced the same problem lately. Have open an issue 
https://github.com/golang/go/issues/37158

On Thursday, February 6, 2020 at 8:53:03 AM UTC+1, Jérôme LAFORGE wrote:
>
>
> I haven't verified this, so this is just a guess, but perhaps without 
>> -trimpath the go tool is using the prebuilt runtime/cgo.a, which was 
>> built on a system with a C compiler.  When you add -trimpath, the 
>> runtime/cgo package needs to be rebuilt in order to trim the paths. 
>> Unfortunately, that rebuild fails, as the system you are building on 
>> does not have a C compiler. 
>>
>
> It would be great to prebuilt runtime/cgo.a also with `-trimpath` option 
> in order  to avoid unobvious dependency with gcc when you have just added 
> `-trimpath` option or at least mention it in `go help build` doc.  
>

-- 
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/386bcc5e-2977-4e8a-9ee5-738b348fa00d%40googlegroups.com.


[go-nuts] Go install speedup within docker

2017-06-11 Thread Vladimir Varankin
Hey James,

Could you show the docker run command, which you invoke to enter a container?

I use docker to build my application as well, so I just do `docker container 
run --rm -ti --volume $PWD:/gocode/src/app --workdir /gocode/src/app 
 go build`. Doing so with container reusage or not, I 
haven't found any speed difference so far.

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go install speedup within docker

2017-06-12 Thread Vladimir Varankin
I think the difference is that I use my project root as my GOPATH, so pkg 
directory ($GOPATH/pkg), which stores the build cache, is mounted inside the 
container every time I run the build. What if you try

```
docker container run --rm -v $PWD:/usr/src/prj -v $PWD/_build:/usr/pkg ...
```

Doing so, should keep pkg caches between builds. Not sure if it still valid, 
but you might consider to switch `go install` (see 
https://dave.cheney.net/2014/06/04/what-does-go-build-build)

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go install speedup within docker

2017-06-12 Thread Vladimir Varankin
"-pkgdir" flag of "go build" / "go install" could also be useful, although 
I haven't tried it.

On Monday, June 12, 2017 at 1:06:49 PM UTC+3, Vladimir Varankin wrote:
>
> I think the difference is that I use my project root as my GOPATH, so pkg 
> directory ($GOPATH/pkg), which stores the build cache, is mounted inside 
> the container every time I run the build. What if you try
>
> ```
> docker container run --rm -v $PWD:/usr/src/prj -v $PWD/_build:/usr/pkg ...
> ```
>
> Doing so, should keep pkg caches between builds. Not sure if it still 
> valid, but you might consider to switch `go install` (see 
> https://dave.cheney.net/2014/06/04/what-does-go-build-build)
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Go at Vimeo in NYC!

2017-09-14 Thread Vladimir Varankin
Do you consider applications from continents other than the US?

On Wednesday, September 13, 2017 at 7:45:11 PM UTC+3, gabr...@vimeo.com 
wrote:
>
> We have lots of jobs programming in Go at Vimeo's headquarters in NYC!
> Please reach out to me at gabr...@vimeo.com  if you or 
> anyone you know may be interested.
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Suggestions about reusing function/method information in comments, swagger, logs, events

2017-09-19 Thread Vladimir Varankin
Hi Brunetto,

While I don't have "a take and go" solution, I have some thoughts to 
discuss.

What I like about swagger and openapi is the ability to abstract the way 
you describe your API's, from the particular implementation. This paradigm 
is (almost) perfectly matches to Go's code generation pattern. 

Looking at how projects like gRPC do things, feels that an API description 
should be written using a sort of a special DSL, which could be used to 
produce implementations (or stubs) for a particular framework. I might be 
wrong, but it looks like Goa (https://github.com/goadesign/goa) uses 
exactly the same approach.

Right now I can't think of any other way that would be integrated into the 
code, so docs and the implementation stayed fresh, and wouldn't bring too 
much overhead to the API's runtime.

What do you think about code generation approach?

Cheers,

Vladimir

On Monday, September 18, 2017 at 10:42:19 PM UTC+3, brunetto wrote:
>
> Hi all!
>
> Given a Go project I write for my company I have (and want) to: 
>
> * write comments on functions/methods (at least the exported ones)
> * write docs for the swagger API docs (using a personal project based on 
> github.com/MarkSonghurst/swag and subpackages) 
> * write few information to be stored in the logs or in the emitted events: 
> function name, purpose (why the function was called), output obtained 
> (~event result from calling the function/method), expected input and 
> possible outputs types and status codes
>
> A lot of information is shared and it would be very nice to avoid copy and 
> past is over and over spreading it through the code. 
> It would be great to have those information bounded in some way to the 
> function/method but I'm open to better ways of thinking.
> A struct with the information with a method returning the function seems 
> wrong to me 
>  
> Can you suggest a way to reduce duplication and approach this matter in a 
> good way?
>
> Good to me means clean, clear to the reader, idiomatic, generic = not 
> bound to a single web framework, play well with custom CI/CD and, most 
> important, not insanely complicated and involuted like the standard swagger 
> comments.  
>
> Thanks a lot
>
> Brunetto
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Why does go run cmd does not accept a directory as an input

2017-11-07 Thread Vladimir Varankin
Currently `go run` accepts a file or a list of ".go" files:

```
% go help run
usage: go run [build flags] [-exec xprog] gofiles... [arguments...]
```

For me, it doesn't seem to be obvious, why can't "go run" accept the 
directory that contains files of the main package as an input?

Note, I'm aware of the ability to pass a list of all main's files, using a 
wildcard selector, e.g. `go run cmg/*.go`. But I want to understand if 
there is any particular reason it works this way, or this is how cmd's 
implemented and the behaviour might be extended in future releases?

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Why does go run cmd does not accept a directory as an input

2017-11-07 Thread Vladimir Varankin
Thank you, Dave, for the response. 

> You’ll have a more enjoyable go experience if you structure your code 
into packages and use go build or preferably go install.

To be fair, I don't think that having the ability to do build + run in one 
go command goes against the fact that it's worth to write code in a proper 
modular way. And I don't see how splitting "main" package into several 
files goes against it as well.

It feels there is nothing wrong with the idea of making "go run" more than 
a command that one should never use in a real project.

Regarding the use of "go build/install", could you talk more, what benefits 
do they provide for the development process. I only aware of incremental 
builds, that speed up the compilation time, which, in my experience, isn't 
that bad for a small/middle size daemons.


On Tuesday, November 7, 2017 at 1:21:52 PM UTC+3, Dave Cheney wrote:
>
> Real talk: go run is for examples as large as one would type into the 
> playground. Nothing more. 
>
> You’ll have a more enjoyable go experience if you structure your code into 
> packages and use go build or preferably go install. 

-- 
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.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Debug high GC pause frequency issue

2018-02-07 Thread Vladimir Varankin
> The CPU profiler told me that the program is spending a lot of time doing 
GC (obviously), and memory profiler is telling me there is a huge amount of 
memory allocated for json encoding/decoding, which is inevitable for 
business logic.

Even though Go is GC based language, Go prefers object re-using to prevent 
extra allocations as much as possible. Check if there are parts of the 
codebase that allocates a lot on the hot path, and if object pooling, 
preallocations, etc, might be applied there.

You may start by switching to alternative json marshallers 
– mailru/easyjson or json-iterator – if this is your case. They were 
developed to handle these particular issues of Go's encoding/json.

On Tuesday, February 6, 2018 at 3:45:56 PM UTC+1, Bob Cao wrote:
>
> Hi Lan
>
> I have used memory profiler and CPU profiler. 
>
> The CPU profiler told me that the program is spending a lot of time doing 
> GC (obviously), and memory profiler is telling me there is a huge amount of 
> memory allocated for json encoding/decoding, which is inevitable for 
> business logic.
>
> And the issue is, it used to be fine. The codebase has been in production 
> for a long time and the average GC per minute used to around 30 per minute, 
> and very stable.
>
> Is there any tip on how should one solve such problems?
>
> Thanks a lot!
>
> On Tuesday, 6 February 2018 22:40:07 UTC+8, Ian Lance Taylor wrote:
>>
>> On Tue, Feb 6, 2018 at 12:58 AM, Bob Cao  wrote: 
>> > 
>> > I have a program whose GC pause frequency will quickly go from 40 calls 
>> per 
>> > minute to 2000 calls per minute in a matter of hours, and the issue is 
>> kind 
>> > of random on production. 
>> > 
>> > Is there any advice on how to spot the cause of the issue? 
>>
>> Use the memory profiler.  See 
>> https://blog.golang.org/profiling-go-programs for some background. 
>>
>> Ian 
>>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Global variable not used, but it works fine

2018-04-23 Thread Vladimir Varankin
I think it's way harder to guaranty that the globals aren't used since even 
non-exported functions/varibles can be used by the linker.

On Saturday, April 21, 2018 at 3:30:22 PM UTC+2, 子風 wrote:
>
>  What did you do?
> https://play.golang.org/p/aryK9Btv5kH
>
>  What did you expect to see?
> There should be a error "declared and not used"
>
>  What did you see instead?
> It seems work fine.
>
>  System details
>
> ```
> go version go1.10.1 windows/amd64
> GOARCH="amd64"
> GOBIN=""
> GOCACHE="C:\Users\zps\AppData\Local\go-build"
> GOEXE=".exe"
> GOHOSTARCH="amd64"
> GOHOSTOS="windows"
> GOOS="windows"
> GOPATH="C:\Users\zps\go"
> GORACE=""
> GOROOT="C:\Go"
> GOTMPDIR=""
> GOTOOLDIR="C:\Go\pkg\tool\windows_amd64"
> GCCGO="gccgo"
> CC="gcc"
> CXX="g++"
> CGO_ENABLED="1"
> CGO_CFLAGS="-g -O2"
> CGO_CPPFLAGS=""
> CGO_CXXFLAGS="-g -O2"
> CGO_FFLAGS="-g -O2"
> CGO_LDFLAGS="-g -O2"
> PKG_CONFIG="pkg-config"
> GOGCCFLAGS="-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments 
> -fmessage-length=0 
> -fdebug-prefix-map=C:\Users\zps\AppData\Local\Temp\go-build846935694=/tmp/go-build
>  
> -gno-record-gcc-switches"
> GOROOT/bin/go version: go version go1.10.1 windows/amd64
> GOROOT/bin/go tool compile -V: compile version go1.10.1
> ```
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Performance regression of HTTP requests since Go 1.11

2018-09-06 Thread Vladimir Varankin
I've seen a similar issue on one of your test hosts and it turned out the 
issue was due to a non-responding NS server in the host's resolv.conf.

See https://github.com/golang/go/issues/27525 DNS regression.

On Wednesday, September 5, 2018 at 5:07:01 PM UTC+2, mrauh wrote:
>
> Thanks for your help!
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Get dependency from enterprise repository

2018-10-09 Thread Vladimir Varankin
Hey there!

I don't know much about jfrog, but was curious to delve into the enterprise 
proxies topic. It seems that you're supposed to use jfrog's own 
jfrog-cli [1] to work with the artifactory. I believe the CLI simply set a 
proper value to GOPROXY to URL, that supports gomod proxy protocol API [2]. 

Check if your artifactory responses with the list from 
"http://stg-repo.com/api/go//@v/list". Note, "/api/go/" prefix is 
seems what jfrog-cli uses [3].

[1]: https://www.jfrog.com/confluence/display/RTF/Go+Registry
[2]: https://tip.golang.org/cmd/go/#hdr-Module_proxy_protocol
[3]: 
https://github.com/jfrog/jfrog-cli-go/blob/a664eede11e6988ca98f53e9541a3113e55112a8/jfrog-cli/artifactory/utils/golang/cmd.go#L52-L62


On Monday, October 8, 2018 at 10:55:41 PM UTC+2, ppras...@splunk.com wrote:
>
> I have built and published the go dependencies to our enterprise 
> artifactory.
> Is there an efficient way to get the files from artifactory and use them 
> in test runs?
>
> My dependencies are in jfrog artifactory.
> They appear like the following:
>
>go-local/github.com/davecgh/go-spew/@v/v1.1.1.zip
>go-local/github.com/davecgh/go-spew/@v/v1.1.1.mod
>
> How should I resolve them when I run my tests?
>
> When I set GOPROXY =“value” and tried,
>
> go get github.com/Masterminds/semver
>
> go get github.com/Masterminds/semver: unexpected status 
> (http://stg-repo.com/artifactory/github.com/%21masterminds/semver/@v/list): 
> 404 Not Found
>
> How can I go get the pkg from enterprise proxy and execute my tests?
>
> As a temporary hack I am doing:
>
>
> Then following
>
> cd **$** {TESTDIR}/src
>
> curl -O http://stg-repo.com/artifactory/ **$** {pkg}
>
> FIELDS=( **$** (echo **$** {pkg} | awk **'{split($0, arr, /[\/:]*/); for (x 
> in arr) { print arr[x] }}'** ))
>
> INDEX=( **$** (echo **$** {FIELDS[@]/@v//} | cut -d/ -f1 | wc -w | tr -d **' 
> '** ))
>
> PREV_INDEX=$INDEX-1
>
> POST_INDEX=$INDEX+1
>
> FILE= **$** {FIELDS[ **$** {POST_INDEX}]}
>
> unzip **$** {FILE}
>
> FILE= **$** (echo **$** {FILE} | sed -e s/^ **$** {go_local}// -e s/ **$** 
> {zip}//)
>
> SOURCE= **$** (find **$** {TESTDIR}/src -name **$** {FIELDS[ **$** 
> {PREV_INDEX}]}@ **$** {FILE})
>
> DIR= **$** (dirname $SOURCE)
>
> mv $SOURCE **$** {DIR}/ **$** {FIELDS[ **$** {PREV_INDEX}]}
>
> rm -rf **$** {FILE}.zip
>
> Please let me know the correct way of doing 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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: blocking profile

2018-11-16 Thread Vladimir Varankin
I believe, "runtime.chanrecv1" is the receiving part of a channel. From 
what you've described, it sounds like you have a dead-lock somewhere. 

In your "out.svg" diagram check what functions are dominating around 
channel read and check if dead-lock is there.


On Thursday, November 15, 2018 at 6:09:15 PM UTC+1, soth...@gmail.com wrote:
>
> Hello,
>
> I'm using four channles, and some TCP connections. 
> It works and one point my server does not get the data over tcp 
> connections.rr
> Still No fatal error or panic error
>
> I tried here and there. Finally I did blocking profile. I show some data.
>
> I run 
> $go tool pprof -svg main blockprofile.prof > out.svg
>
> It shows 99.4% it is waiting for runtime.chanrecv1. 
>
> I dont know how to interpret those result?  What I have to do for 
> detecting the casue for above problem?
>
> Best regards
> Sothy
>
>
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Discrepancy between htop and memstats

2019-05-01 Thread Vladimir Varankin
Hi Michel,

Have tried collecting your program's heap profiles [1] (maybe once after 
each reload cycle)? Comparing pprof results should show you what objects 
leak memory.

[1]: https://blog.golang.org/profiling-go-programs

On Tuesday, April 30, 2019 at 3:36:34 PM UTC+2, Michel Levieux wrote:
>
> Hi all,
>
> I'm currently having a lot of trouble debugging the memory usage of the 
> program I'm working on. This program, everyday at a given time, reloads a 
> bunch of data (that's been updated by another program) into its memory. The 
> following function:
>
> // PrintMemUsage outputs the current, total and OS memory being used. As 
> well as the number
> // of garage collection cycles completed.
> func PrintMemUsage() {
> var m runtime.MemStats
> runtime.ReadMemStats(&m)
> // For info on each, see: https://golang.org/pkg/runtime/#MemStats
> fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
> fmt.Printf("TotalAlloc = %v MiB", bToMb(m.TotalAlloc))
> fmt.Printf("Sys = %v MiB", bToMb(m.Sys))
> fmt.Printf("NumGC = %v\n", m.NumGC)
> }
>
> Outputs this:
>
> Alloc = 103861 MiB
> TotalAlloc = 6634355 MiB
> Sys = 232088 MiB
> NumGC = 3822
>
> The program reloads its data everyday but everyday the few references that 
> existed for the given data is overwritten by the new one. And indeed the 
> "Alloc" line above seems to stay around 100GB. Where I don't understand 
> what happens is that in the htop line of the program, the memory that is 
> used by the program keeps growing as the days pass, and when it reaches 
> close to 100% percent of the host's memory, the program will crash 
> eventually.
>
> Any idea that would help me debug this memory inconstency between memstats 
> and htop is welcome. I can also provide more information but no particular 
> piece of code directly from the project.
>
> Thank you all 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.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Proper way of mocking interfaces in unit tests - the golang way

2020-10-02 Thread Vladimir Varankin
Hey,

I don't think the statement about "assert going against the best practices 
in go unit tests" stands against the reality, sorry. One definitely doesn't 
have to use a separate assertion package to write unit-tests in Go, 
comparing to some other programming languages. But there is really no much 
difference between using an assertion of t.Fail-ing manually.

In our project, we use testify assertions (only for statistics: our 
monorepo is ~400K lines of Go code with every package covered with 
unit-tests) and it works great just by reducing the total number of lines 
in our test files and making them much more manageable (we have unit-tests 
files that over years has grown over 3K+ LOC now).

Depending on the interface, we usually create a separate "controlled" 
implementation, that we use in unit-tests. E.g. if we implemented a 
DataStore, we would have an in-memory implementation with additional 
Setter-methods, that accepted an optional "hook", that allowed us to return 
an error.

We don't use "testify/mock" because we aren't interested in verifying the 
calls or the arguments that were passed to the mock. Usually, it's easier 
to write a fake implementation. I.e. our testing implementations are more 
"fakes" than "mocks".

One neat thing about that approach is that testing implementation doesn't 
always have to expose lots of knobs. If one unit-test needs to tune the 
behaviour, you can always stub the dependency right in-place and use it for 
this single test only. E.g.

type testDataStore struct {
callFooFunc() error
}

func (s *testDataStore) Foo() error {
return s.callFooFunc()
}

func TestSomething(t *testing.T) {
ds := &testDataStore {
callFooFunc: func() error {
   return fmt.Errorf("a very specific error that make sence to test 
against in this test only")
}
}
// ···
}

Hope that makes sense.

On Thursday, October 1, 2020 at 6:26:19 PM UTC+2 krish...@gmail.com wrote:

> We are working on a full scale production app with go backend.
>
> For unit tests, we need to mock the dependent interfaces either by 
> creating our own mock implementation of the interface or by using third 
> party packages like *testify/mocks.*
>
> If we use testify, there will be a tendency for the developers to use *assert 
> *statements which is against the best practices in go unit tests. (We use 
> t.Fail instead of asserts)
>
> If we create manual mocks, we will end up creating two implementations for 
> each interface, one for the program and another for the unit testing. Also 
> we cannot test by mocking with different outputs from the dependencies. 
> example if the dependency return an error.
>
> Please suggest which the right approach here.
>

-- 
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/6102c3f1-d398-4e0b-9cc8-fc4a848f4c7bn%40googlegroups.com.


Re: [go-nuts] Re: Proper way of mocking interfaces in unit tests - the golang way

2020-10-05 Thread Vladimir Varankin
> Or, it will be written as assert.Equal(got, want,
fmt.Sprintf("MyFunction(%v)", input)), but that is harder to write, and
therefore less likely to be written.

That obviously depends on the implementation details but since we talk
about testify the API is: assert.Equal(t, want, got, format, [args...]).

On Mon, 5 Oct 2020 at 18:45, Ian Lance Taylor  wrote:

> On Mon, Oct 5, 2020 at 8:47 AM Viktor Kojouharov 
> wrote:
> >
> > I don't find any difference between calling t.Errorf and
> assert.Something with a provided message. Both will populate the test log,
> with the later giving you more details exactly where things differ from the
> expectation.
>
> The difference is that since people write t.Error while writing the
> test, it's very easy to provide all the relevant information, which in
> many cases will involve more than just the values being compared.  A
> common example would be a message like "MyFunction(%v) = %v, want %v".
> When using an assert style function, the message will tend to lose the
> value passed to MyFunction.  Or, it will be written as
> assert.Equal(got, want, fmt.Sprintf("MyFunction(%v)", input)), but
> that is harder to write, and therefore less likely to be written.
> (It's also less efficient in the common case, though for a test that
> is unlikely to matter.)
>
> Ian
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/ZoJ5isoeea4/unsubscribe.
> To unsubscribe from this group and all its topics, 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/CAOyqgcXNV6bLQQUFmVn14xnxheALTKbv1_oQODovboLEziPKSw%40mail.gmail.com
> .
>


-- 
Vladimir Varankin
vladi...@varank.in

-- 
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/CAGLqCMmj7NB3Sem0BDdyJBj-cxGXVmBY-6StRXAP6MvwZUyOnQ%40mail.gmail.com.


[go-nuts] Re: How to implement localhost proxy which injects Proxy-Authorization header to incoming request and sends it to another remote proxy with Go?

2021-03-16 Thread Vladimir Varankin
Hey there,

Seems the issue hides in the chunk, where you overwrite reverse proxy's 
"Director" method, which NewSingleHostReverseProxy creates internally. 
Since your own director doesn't set the client request's Schema and Host, 
you have to either do that manually or make sure you call the original 
director.

Try doing the following:

proxyDirector := proxy.Director // ← keep the original director
d := func(req *http.Request) {
logrus.Infof("Pre-Edited request: %+v\n", req)

proxyDirector(req) // ← call the original director to make sure the 
request will go through the proxy

// Inject proxy authentication headers to outgoing request into new 
Header
basicAuth := "Basic " + 
base64.StdEncoding.EncodeToString([]byte(remoteServerAuth))
req.Header.Set("Proxy-Authorization", basicAuth)
logrus.Infof("Edited Request: %+v\n", req)
logrus.Infof("Scheme: %s, Host: %s, Port: %s\n", req.URL.Scheme, 
req.URL.Host, req.URL.Port())
}
proxy.Director = d

Also, have a look at the implementation of NewSingleHostReverseProxy 
https://go.googlesource.com/go/+/go1.16/src/net/http/httputil/reverseproxy.go#142

Cheers,
V.

On Monday, March 15, 2021 at 11:37:51 PM UTC+1 hugo@gmail.com wrote:

> Hi!
> I'm actually building an automation tool based on Selenium with Go called 
> IGopher and I have had a few requests to implement native proxy support.  
> However, I am facing an issue with those with authentication...  
> I can't send the proxy credentials to Chrome and without them it asks 
> through an alert box for authentication that I can hardly interact with 
> through Selenium (I'm not even sure it's possible in headless mode) .
>
> So I thought of an intermediary proxy system hosted locally by my program 
> which will add the *Proxy-Authorization* header and transfer the request 
> to the remote proxy:
>
> [image: IGopher_proxies.jpg]
>
> Something like this:  proxy-login-automator 
> 
>
> I'm not very familiar with proxies to be honest, but I tried this approach 
> using *NewSingleHostReverseProxy*: 
> ```go
> var (
> localServerHost  string
> remoteServerHost string
> remoteServerAuth string
> )
>
> // ProxyConfig store all remote proxy configuration
> type ProxyConfig struct {
> IP   string `yaml:"ip"`
> Port int`yaml:"port"`
> Username string `yaml:"username"`
> Password string `yaml:"password"`
> Enabled  bool   `yaml:"activated"`
> }
>
> func PrintResponse(r *http.Response) error {
> logrus.Infof("Response: %+v\n", r)
> return nil
> }
>
> // LaunchForwardingProxy launch forward server used to inject proxy 
> authentication header
> // into outgoing requests
> func LaunchForwardingProxy(localPort uint16, remoteProxy ProxyConfig) 
> error {
> localServerHost = fmt.Sprintf("localhost:%d", localPort)
> remoteServerHost = fmt.Sprintf(
> "http://%s:%d";,
> remoteProxy.IP,
> remoteProxy.Port,
> )
> remoteServerAuth = fmt.Sprintf(
> "%s:%s",
> remoteProxy.Username,
> remoteProxy.Password,
> )
>
> remote, err := url.Parse(remoteServerHost)
> if err != nil {
> panic(err)
> }
>
> proxy := httputil.NewSingleHostReverseProxy(remote)
> d := func(req *http.Request) {
> logrus.Infof("Pre-Edited request: %+v\n", req)
> // Inject proxy authentication headers to outgoing request into new Header
> basicAuth := "Basic " + 
> base64.StdEncoding.EncodeToString([]byte(remoteServerAuth))
> req.Header.Set("Proxy-Authorization", basicAuth)
> logrus.Infof("Edited Request: %+v\n", req)
> logrus.Infof("Scheme: %s, Host: %s, Port: %s\n", req.URL.Scheme, 
> req.URL.Host, req.URL.Port())
> }
> proxy.Director = d
> proxy.ModifyResponse = PrintResponse
> http.ListenAndServe(localServerHost, proxy)
>
> return nil
> }
> ```
>
> With this code snippet, I'm able to intercept the request and update the 
> header. 
> However, resending the CONNECT request fails with the following output:
>
> ```
> INFO[0028] Pre-Edited request: &{Method:CONNECT URL://google.com:443 
> Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 
> Header:map[Proxy-Connection:[Keep-Alive] User-Agent:[curl/7.68.0]] 
> Body: GetBody: ContentLength:0 TransferEncoding:[] Close:false 
> Host:google.com:443 Form:map[] PostForm:map[] MultipartForm: 
> Trailer:map[] RemoteAddr:127.0.0.1:35610 RequestURI:google.com:443 
> TLS: Cancel: Response: ctx:0xc000164300}  function=func1 
> line=59
>
> INFO[0028] Edited Request: &{Method:CONNECT URL://google.com:443 
> Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 
> Header:map[Proxy-Authorization:[Basic ] Proxy-Connection:[Keep-Alive] 
> User-Agent:[curl/7.68.0]] Body: GetBody: ContentLength:0 
> TransferEncoding:[] Close:false Host:google.com:443 Form:map[] 
> PostForm:map[] MultipartForm: Trailer:map[] RemoteAddr:
> 127.0.0.1:35610 RequestURI:google.com:443 TLS: Cancel: 
> Response: ctx:0xc000164300}  function=func1 line=63
>
> INFO[0028] Scheme: , Host: google.com:443, Port: 443 function=func1 
> line=64
>
> *2021/03/15 21:35:11 http: pr

[go-nuts] Re: How to implement localhost proxy which injects Proxy-Authorization header to incoming request and sends it to another remote proxy with Go?

2021-03-17 Thread Vladimir Varankin
I think I didn't get what you're building right. Now, it looks like, 
instead of implementing a custom RR's director, you need to configure its 
Transport [1], which will be aware of your auth proxy in the middle. Have a 
look at net/http.Transport.Proxy field [2] for that.

[1]: https://pkg.go.dev/net/http/httputil?utm_source=godoc#ReverseProxy
[2]: https://pkg.go.dev/net/http?utm_source=godoc#Transport

On Tuesday, March 16, 2021 at 11:17:49 AM UTC+1 hugo@gmail.com wrote:

> Thank you for your advice that I applied.
> But now I have a *407 Proxy Authentication Required* error, while the 
> header is added to the request...
> Here is the output:
>
> INFO[0019] Pre-Edited request: &{Method:CONNECT URL://google.com:443 
> Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 
> Header:map[Proxy-Connection:[Keep-Alive] User-Agent:[curl/7.68.0]] 
> Body: GetBody: ContentLength:0 TransferEncoding:[] Close:false 
> Host:google.com:443 Form:map[] PostForm:map[] MultipartForm: 
> Trailer:map[] RemoteAddr:127.0.0.1:45382 RequestURI:google.com:443 
> TLS: Cancel: Response: ctx:0xc000814240}  function=func1 
> line=60
>
> INFO[0019] Edited Request: &{Method:CONNECT URL:http://51.178.xx.xx:3128/ 
> Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 
> Header:map[Proxy-Authorization:[Basic ] Proxy-Connection:[Keep-Alive] 
> User-Agent:[curl/7.68.0]] Body: GetBody: ContentLength:0 
> TransferEncoding:[] Close:false Host:google.com:443 Form:map[] 
> PostForm:map[] MultipartForm: Trailer:map[] RemoteAddr:
> 127.0.0.1:45382 RequestURI:google.com:443 TLS: Cancel: 
> Response: ctx:0xc000814240}  function=func1 line=69
>
> INFO[0019] Scheme: http, Host: 51.178.xx.xx:3128, Port: 3128  
> function=func1 line=70
>
> INFO[0019] Response: &{Status:407 Proxy Authentication Required 
> StatusCode:407 Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 
> Header:map[Content-Language:[en] Content-Length:[3520] 
> Content-Type:[text/html;charset=utf-8] Date:[Tue, 16 Mar 2021 10:03:44 GMT] 
> Mime-Version:[1.0] Server:[squid/3.5.27] Vary:[Accept-Language] Via:[1.1 
> vps799016 (squid/3.5.27)] X-Cache:[MISS from vps799xxx] 
> X-Cache-Lookup:[NONE from vps799xxx:3128] 
> X-Squid-Error:[ERR_CACHE_ACCESS_DENIED 0]] Body:0xc0004de180 
> ContentLength:3520 TransferEncoding:[] Close:false Uncompressed:false 
> Trailer:map[] Request:0xc0005ee100 TLS:}  function=PrintResponse 
> line=33
>
>
> PS: Is it possible on Google Groups to format code snippets? Markdown not 
> seems to be supported
>
> Le mardi 16 mars 2021 à 09:04:31 UTC+1, vlad...@varank.in a écrit :
>
>> Hey there,
>>
>> Seems the issue hides in the chunk, where you overwrite reverse proxy's 
>> "Director" method, which NewSingleHostReverseProxy creates internally. 
>> Since your own director doesn't set the client request's Schema and Host, 
>> you have to either do that manually or make sure you call the original 
>> director.
>>
>> Try doing the following:
>>
>> proxyDirector := proxy.Director // ← keep the original director
>> d := func(req *http.Request) {
>> logrus.Infof("Pre-Edited request: %+v\n", req)
>>
>> proxyDirector(req) // ← call the original director to make sure 
>> the request will go through the proxy
>>
>> // Inject proxy authentication headers to outgoing request into 
>> new Header
>> basicAuth := "Basic " + 
>> base64.StdEncoding.EncodeToString([]byte(remoteServerAuth))
>> req.Header.Set("Proxy-Authorization", basicAuth)
>> logrus.Infof("Edited Request: %+v\n", req)
>> logrus.Infof("Scheme: %s, Host: %s, Port: %s\n", req.URL.Scheme, 
>> req.URL.Host, req.URL.Port())
>> }
>> proxy.Director = d
>>
>> Also, have a look at the implementation of NewSingleHostReverseProxy 
>> https://go.googlesource.com/go/+/go1.16/src/net/http/httputil/reverseproxy.go#142
>>
>> Cheers,
>> V.
>>
>> On Monday, March 15, 2021 at 11:37:51 PM UTC+1 hugo@gmail.com wrote:
>>
>>> Hi!
>>> I'm actually building an automation tool based on Selenium with Go 
>>> called IGopher and I have had a few requests to implement native proxy 
>>> support.  
>>> However, I am facing an issue with those with authentication...  
>>> I can't send the proxy credentials to Chrome and without them it asks 
>>> through an alert box for authentication that I can hardly interact with 
>>> through Selenium (I'm not even sure it's possible in headless mode) .
>>>
>>> So I thought of an intermediary proxy system hosted locally by my 
>>> program which will add the *Proxy-Authorization* header and transfer 
>>> the request to the remote proxy:
>>>
>>> [image: IGopher_proxies.jpg]
>>>
>>> Something like this:  proxy-login-automator 
>>> 
>>>
>>> I'm not very familiar with proxies to be honest, but I tried this 
>>> approach using *NewSingleHostReverseProxy*: 
>>> ```go
>>> var (
>>> localServerHost  string
>>> remoteServerHost string
>>> remoteServerAuth string
>>> )
>>>
>>> // ProxyConfig store all remote proxy configuration
>>> type Proxy

[go-nuts] Re: signal.NotifyContext - Does it expose the signal handled?

2021-05-14 Thread Vladimir Varankin
I don't think the current API provides that functionality.

In the original proposal for signal.NotifyContext, there were several 
discussions, including related to what features the new API should provide. 
The consensus was that if a user wants to make a decision base on the 
signal caught, they should use "signal.Notify", as the low-level API, which 
allows that (refer to this issue https://github.com/golang/go/issues/37255).

On Thursday, May 13, 2021 at 10:54:39 PM UTC+2 amits...@gmail.com wrote:

> Hi - i took a brief look and it doesn't look like we can access the
> signal that was handled via the signal.NotifyContext() function call?
> It could be useful for logging messages.
>

-- 
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/b7b21dd2-b12a-4a01-b2f0-3dee10778cd1n%40googlegroups.com.


[go-nuts] Re: arm64 builder on raspberry pi 3B/3B+

2020-02-13 Thread Vladimir Varankin
Note, Ubuntu Server 19.10 (arm64) works out of the box on Raspberry Pi 3 
and 4, It might be an easier option. 

I've written about my experience of running 19.10 on Pi 4 [1]. But I didn't 
manage to run 18.04 — headless mode just didn't work and I didn't have 
opportunity to attach a keyboard and a monitor to figure out what was 
happening.

[1]: https://vladimir.varank.in/notes/2020/01/raspi-ubuntu-arm64-k3s/

On Wednesday, February 12, 2020 at 4:33:04 AM UTC+1, kortschak wrote:
>
> I have been wanting an arm64 builder to do local testing for Gonum 
> recently. Unfortunately, though RPi 3 and 4 have 64 bit cores, Raspbian 
> is 32 bit, so they don't satisfy. 
>
> However, I found this article[1] which goes through installing a UEFI 
> bootloader and vanilla Debian Buster install on 3B/3B+. 
>
> I tried it out yesterday and it worked perfectly (making sure to follow 
> the instructions to the letter). 
>
> There is also a UEFI bootloader setup for the RPi4[2], but it is 
> currently experimental. 
>
> Dan 
>
> [1]
> https://pete.akeo.ie/2019/07/installing-debian-arm64-on-raspberry-pi.html 
> [2]https://github.com/pftf/RPi4 
>
>
>

-- 
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/78042369-405e-47be-8d61-63e2aaf88c16%40googlegroups.com.


[go-nuts] Re: directory name and module name not same, go tool pprof, list function faild

2020-07-31 Thread Vladimir Varankin
Hey,

In your example, "~/Documents/tool/tejia_analysis" is your module's source 
root, right? Could you show where "app_server/util/analysis.go" is on the 
FS and what is the name of the module?

pprof has a coupe flags to manipulate with the path, helping it to search 
for the source code. I used to use the combination of "-source_path" and 
"-trim_path" to map my local source code to the paths that were embedded 
into the app's binary.

On Thursday, July 30, 2020 at 8:09:29 AM UTC+2 blade...@gmail.com wrote:

> hi, i create a project, directory name and module name not same, and i 
> profile it , use list command  to print code and profile, it tips me not 
> find the file,  how to make it works?
>
>
> macbookpro:tejia_analysis fredlee$ go tool pprof 
> http://ip:6065/debug/pprof/heap
>
> Fetching profile over HTTP from http://ip:6065/debug/pprof/heap
>
> Saved profile in 
> /Users/fredlee/pprof/pprof.tejia_analysis.alloc_objects.alloc_space.inuse_objects.inuse_space.006.pb.gz
>
> File: tejia_analysis
>
> Type: inuse_space
>
> Time: Jul 30, 2020 at 2:03pm (CST)
>
> Entering interactive mode (type "help" for commands, "o" for options)
>
> (pprof) top20 -cum
>
> Showing nodes accounting for 2509.12MB, 98.97% of 2535.11MB total
>
> Dropped 37 nodes (cum <= 12.68MB)
>
>   flat  flat%   sum%cum   cum%
>
>  0 0% 0%  2533.11MB 99.92%  app_server/util.(*Analysis).Job
>
>  0 0% 0%  2533.11MB 99.92%  
> app_server/util.(*Analysis).Start
>
>  1007.72MB 39.75% 39.75%  2523.10MB 99.53%  
> app_server/util.(*Analysis).LoadSearchLog
>
>  0 0% 39.75%  1466.37MB 57.84%  
> go.mongodb.org/mongo-driver/bson.(*Decoder).Decode
>
>  0 0% 39.75%  1466.37MB 57.84%  
> go.mongodb.org/mongo-driver/bson.UnmarshalWithRegistry
>
>  0 0% 39.75%  1466.37MB 57.84%  
> go.mongodb.org/mongo-driver/bson.unmarshalFromReader
>
>  0 0% 39.75%  1466.37MB 57.84%  
> go.mongodb.org/mongo-driver/bson/bsoncodec.(*StructCodec).DecodeValue
>
>  0 0% 39.75%  1466.37MB 57.84%  
> go.mongodb.org/mongo-driver/mongo.(*Cursor).Decode (inline)
>
>  0 0% 39.75%  1457.37MB 57.49%  
> go.mongodb.org/mongo-driver/bson/bsoncodec.(*StringCodec).DecodeValue
>
>  0 0% 39.75%  1457.37MB 57.49%  
> go.mongodb.org/mongo-driver/bson/bsonrw.(*valueReader).ReadString
>
>  1457.37MB 57.49% 97.24%  1457.37MB 57.49%  
> go.mongodb.org/mongo-driver/bson/bsonrw.(*valueReader).readString
>
>  0 0% 97.24%44.03MB  1.74%  net/url.ParseQuery (inline)
>
>44.03MB  1.74% 98.97%44.03MB  1.74%  net/url.parseQuery
>
> (pprof) list LoadSearchLog
>
> Total: 2.48GB
>
> ROUTINE  app_server/util.(*Analysis).LoadSearchLog 
> in app_server/util/analysis.go
>
>  1007.72MB 2.46GB (flat, cum) 99.53% of Total
>
>  Error: could not find file app_server/util/analysis.go on path 
> /Users/fredlee/Documents/tool/tejia_analysis
>
>
>

-- 
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/720fbe94-a27b-457c-8be8-30b28b5fbd2fn%40googlegroups.com.


[go-nuts] Re: Mysterious RSS memory spike

2020-08-24 Thread Vladimir Varankin
Hey,

I haven't looked deep but I recall there had been a note about runtime 
change in Go 1.13's https://golang.org/doc/go1.13#runtime That is

> The runtime is now more aggressive at returning memory to the operating 
system to make it available to co-tenant applications [..] However, on many 
OSes, including Linux, the OS itself reclaims memory lazily, so process RSS 
will not decrease until the system is under memory pressure. 

Could that be the behaviour you observe (although, since you don't see the 
same in C implementation, I might be confused, sorry in advance).

On Sunday, August 23, 2020 at 5:05:22 PM UTC+2 Manish Rai Jain wrote:

> Hey Gophers,
>
> I'm puzzled by a mysterious RSS memory spike in my Go program, when all 
> memory allocations are happening via Cgo. I assert that there are no memory 
> leaks in the program. And have written another C program with similar logic 
> which does NOT show RSS memory spiking. So, I suspect this is something to 
> do with Go memory.
>
> 
> Program:
>
> https://github.com/dgraph-io/ristretto/pull/186
>
> This PR creates a Go memtest program, which does this:
> - Uses z.Calloc and z.Free to allocate Go struct (S) and a byte slice 
> inside it. All allocations are happening in Cgo, and being type casted into 
> Go. No allocations are happening in Go (except a 32 MB fill slice).
> - z.NumAllocBytes is tracking memory allocated and freed by these calls.
> - Increases memory usage to 16 GB (as reported by z.NumAllocBytes).
> - Decreases it back to 1 GB.
> - Repeats this cycle.
> - On Ctrl+C, it deallocates everything and asserts that Cgo memory 
> allocated is zero.
>
> I was concerned about memory fragmentation, so created a very similar C 
> program which does the same thing (memtestc).
>
> Please feel free to run either of the Go or C programs. They should 
> compile and run easily.
>
> Behavior:
>
> Run the program with: `go build . && ./memtest` . Go pprof heap shows 32 
> MB used, to account for the fill slice. However, RSS reported keeps roughly 
> increasing every cycle.
>
> I'm using Go 1.14.4 and on it, RSS jumps to 22GB after a few cycles. memtestc 
> (C equivalent, compiled with gcc) does not show this behavior. The RSS goes 
> down to 1GB-ish every cycle.
>
> Any clues why the RSS is much higher than expected in Go and keeps 
> climbing in Go?
>
> —
> Manish
> Founder, https://dgraph.io
>

-- 
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/02c12495-689d-4eb7-8c09-eeba1f790f63n%40googlegroups.com.


[go-nuts] Re: What books/tutorail/resources/blog for newcomer to golang?

2020-09-16 Thread Vladimir Varankin
Hey!

My peaks, that helped me a lot, back when I started with Go (depending on 
what's your prefered way to learn and how fast do you have to learn it, 
some might be less useful than the others. But it's worth to have the 
options):

- Books
Go in Action — an extreamly good introduction to the language
Go Programming Blueprints — this one is focusing on some small but 
practical examples

- Docs
https://github.com/golang/go/wiki/CodeReviewComments — worth getting 
familiar after some time; it'd help with the understanding why lots of Go 
code in the wild is written in the way it's written ;)

- Video series (YouTube)
Go in 5 minutes
Just for func

- Blogs (no particular order)
https://www.ardanlabs.com/blog/
https://blog.gopheracademy.com/
https://dave.cheney.net/category/golang
https://peter.bourgon.org/blog/

Hope that will help.

On Tuesday, September 15, 2020 at 5:41:38 PM UTC+2 sachin...@gmail.com 
wrote:

> If i had to learn golang now what are the best books/resources/blogs to 
> start with.  Thanks

-- 
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/e1c35720-af2c-4522-9403-dd655a01fda1n%40googlegroups.com.


[go-nuts] Re: Better dependency management in go

2020-09-23 Thread Vladimir Varankin
Hey!

Several months ago I opened the proposal for extending the systax of go.mod 
in order to allow to specify/overwrite the source URL for a dependency 
(https://github.com/golang/go/issues/39536). It feels it could also solve 
what you described in "Problem 1", although the motivation behind the 
proposal is a bit different.

Let me know what you think.

On Tuesday, September 22, 2020 at 12:02:01 AM UTC+2 shirshendu...@gmail.com 
wrote:

> Hi All,
>
> I create a github issue to suggest a proposal for making go dependency 
> managment better.
>
> As people there suggested that this group is probably the best place to 
> discuss this, I am posting the exact same post here:
>
> Even after the introduction of Go modules, the dependency management is 
> complex and not so developer friendly. For beginners it takes a good amount 
> of time to understand what's going on behind the scene.
>
> Some of this may be because of lack of well written documentation about 
> dependency management.
>
>- 
>
>There are some confusing syntax, for example
>github.com/myorganzation/mypackage/pkg
>
>This url results in 404 in browsers but somehow go resolves it, so it 
>seems like depending on hosting providers such as GitHub, BitBucket etc go 
>have different mechanisms of resolving the URL.
>
>Which is somewhat described in here 
>
>- 
>
>Upgrading to major version with a suffix like vX
>- 
>
>Though i am not sure about this but i didn't find any way by which i 
>can tell that this indirect dependency x is from the dependency y, just by 
>looking into go.sum or go.mod files.
>- 
>
>Error messages not being so helpful
>If i try to go get a package in a directory which is not a module i 
>get an error message which is not so helpful for beginners
>
> go get github.com/gofiber/fiber/v2 cannot find package "
> github.com/gofiber/fiber/v2" in any of: /usr/local/go/src/
> github.com/gofiber/fiber/v2 (from $GOROOT) 
> /Users/shirshendubhowmick/go/src/github.com/gofiber/fiber/v2 (from 
> $GOPATH)
>
>- There is no easy way of adding dev only dependencies.
>
> Gophers please do let me know your thoughts about this, also request you 
> to think about these issues from a beginners perspective especially if 
> someone is coming from JavaScript or Python background.
>
> I feel like there is a steep learning curve for go dependency management, 
> which can be made easy with little changes in go and it's documentation.
>
> *Edit: Adding some suggestion to deal with the problems I mentioned above*
> Some high level suggestion to deal with the current problems
>
>- 
>
>*Problem 1:* The current way of downloading, using & maintaining a 
>package
>
>I like the idea of not having a central registry like npm or pip. 
>However using repo URLs (that is also some modified URL) everywhere in the 
>codebase to import the package doesn't seem to be the best way.
>
>Instead what we can do is use git URLs git+ssh://
>g...@github.com/myorganization/mypackage 
> (HTTPS url works 
>too), only at one place, i.e. our dependency file (currently go.mod)
>With this, we can also refer to a particular branch, tag or commit.
>
>Now our dependency file (currently go.mod) will have a mapping of 
>module name and its URL to create an alias for the module, for example
>mypackage git+ssh://g...@github.com/myorganization/mypackage 
>
>
>Everywhere in the code base a consumer will use the alias name instead 
>of a URL to import the package, for example
>
>import "mypackage"
>
>Now how do we know where the module is located inside the repo ? Right 
>now we add a go.mod file in every module root directory. With this change 
>maybe we can add a single file in the repo root which will tell where the 
>modules are located relative to the repo root. I guess this will give more 
>flexibility to both the module developer and consumer.
>
>For updating version, we can either do it manually by changing the URL 
>or maybe via some tool like go update mypackage
>- 
>
>*Problem 2:* Improving the error messages
>This might be a simpler problem to solve compared to the above one. 
>There is no specific solution to this. I think the best way is to run an 
>audit to figure out point of failures while working with modules in go. 
> And 
>try to have as much meaningful error message as possible with some 
> detailed 
>log.
>
> This is very high level solution proposal, happy to discuss more on it and 
> also pros & cons, gotchas, bottlenecks etc.
>
> Original github issue link:
> https://github.com/golang/go/issues/41510
>

-- 
You received this message because you are subscrib