[go-nuts] What happened to the Pholcus crawler?

2019-12-26 Thread Darko Luketic
I had a notification about some issue I commend on 
in https://github.com/henrylee2cn/pholcus

Pholcus was a crawler written in Go, no English docs. I starred it, along 
with about 6200 others.

I assume the guy was bullied by the Chinese government or parts of it, 
maybe killed, who knows, because his status shows "Cease to programing and 
cease to live.",
because the readme says strange things:

Pholcus (source removed)
> Disclaimer
>
> This software is only used for academic research, but because of frequent 
> occurrences of crawler developers in China related to news related to 
> violations, the source code of this library has been deleted. At the same 
> time, academic enthusiasts who have downloaded this software are strongly 
> recommended to delete the source code as soon as possible.
> Solemnly declare: The user must abide by the relevant laws and regulations 
> of his location. The user shall bear all the consequences caused by 
> illegal and illegal use! !!


This is translated with Google Translate, the original text can be found in 
the readme.

What happened there?
When people get bullied or killed over software then something is wrong (I 
remind you about the truecrypt incident) then a Streisand effect must 
happen, e.g. a spotlight needs to shine on that issue.
Maybe it was removed for copyright violations (the right holders suing the 
crawlers, might as well happen in the EU with the new laws passed recently 
and I hear the US is having similar talks).
Maybe it's just a marketing ploy, https://github.com/pholcus-go/pholcus 
exists with a fork from 25 nov 2019, the github organisation was created on 
24 dec 2019, the same day the https://github.com/henrylee2cn/pholcus repo 
was zeroed.

If anyone knows what happened, please enlighten us.

I find that all very suspicious.

-- 
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/d55b1eaa-ffbd-48ba-8755-43ebbb7f89ae%40googlegroups.com.


[go-nuts] Re: go mod dependency hell is real

2019-09-13 Thread Darko Luketic
Hey Sam and Pudds,

thanks for feedback and help. v1.1.7 helped.
I must say go.mod is growing on me, but it's still hindering productivity 
or let's say a step back.

If you use Goland, which probably most mousepushers like me use, since 
everything is under ~/go/pkg/
even with modules enabled in the IDE, if you don't know the exact type, it 
won't autocomplete anymore
And for each subdirectory that is not yet "connected" to the main package 
or root level updating imports and go.mod/sum needs to be done seperately
or else you won't have code completion.
So this involves finding the package name, going to their repository then 
finding the godoc reference, clicking on it, and searching on the page for 
the correct type.
For instance I forgot
r := gin.Default()
was it gin.New() or was it gin.NewRouter() ? I forgot.
So I had to do the whole jazz wasting time.
Previous to go modules, it's in ~/go/src/ the IDE had indexed the paths and 
it's available.

Now you can say, "that's not a Go modules problem, that's the IDE". Well 
yeah but the factual reality is, it's a step backwards in productivity.
Maybe it really is an IDE issue and it doesn't happen in vim.

Another concern is this Google proxy by default. That is really something I 
find feels like betrayal.
I didn't know every go modules request goes through a Google proxy by 
default until I read more about the modules topic.
And the resolution of this problem wasn't very obvious, but I had to read 
through obscure documentation.
Read the privacy policy if you can find it, then read the rather long 
document (longer than a simple: here's the one-line that turns off this 
builtin spyware)
All leaving a sour taste.

I wonder what kind of spyware Go v2 will include by default.
Not happy.

-- 
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/533438a6-cf56-4d33-acbf-a656abd4ede2%40googlegroups.com.


[go-nuts] Re: go mod dependency hell is real

2019-09-10 Thread Darko Luketic
The answer is apparently
https://github.com/gin-gonic/gin/issues/2039#issuecomment-527997733

Add this to your go.mod file:
> replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go 
> v0.0.0-20190204201341-e444a5086c43


On Tuesday, September 10, 2019 at 2:48:25 PM UTC+2, Darko Luketic wrote:
>
> What used to work pre go 1.13 now doesn't work anymore
>
> go mod is one big mess no one needs and complicates everything
> I'm now getting ambiguity. How do I resolve it?
> Nothing compiles anymore
>
>  ✘ darko@wrk  ~/go/src/git.icod.de/dalu/socialthing   master ●✚  go 
> mod tidy
> go: extracting github.com/ugorji/go/codec 
> v0.0.0-20181204163529-d75b2dcb6bc8
> git.icod.de/dalu/socialthing/cmd imports
> github.com/gin-gonic/gin/binding imports
> github.com/ugorji/go/codec: ambiguous import: found 
> github.com/ugorji/go/codec in multiple modules:
> github.com/ugorji/go v1.1.4 (/home/darko/go/pkg/mod/
> github.com/ugorji/go@v1.1.4/codec)
> github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 
> (/home/darko/go/pkg/mod/
> github.com/ugorji/go/codec@v0.0.0-20181204163529-d75b2dcb6bc8)
>
>
> What does that even mean?
> Why?
> How do I fix this?
> How do I permanently disable go mod?
> I don't want it, I don't need it.
>
> build git.icod.de/dalu/socialthing: cannot load github.com/ugorji/go/codec: 
> ambiguous import: found github.com/ugorji/go/codec in multiple modules:
> github.com/ugorji/go v1.1.4 (/home/darko/go/pkg/mod/
> github.com/ugorji/go@v1.1.4/codec)
> github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 
> (/home/darko/go/pkg/mod/
> github.com/ugorji/go/codec@v0.0.0-20181204163529-d75b2dcb6bc8)
>
> /wrist
>

-- 
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/3f90b8db-502b-4eca-997e-bf9202c21c46%40googlegroups.com.


[go-nuts] go mod dependency hell is real

2019-09-10 Thread Darko Luketic
What used to work pre go 1.13 now doesn't work anymore

go mod is one big mess no one needs and complicates everything
I'm now getting ambiguity. How do I resolve it?
Nothing compiles anymore

 ✘ darko@wrk  ~/go/src/git.icod.de/dalu/socialthing   master ●✚  go mod 
tidy
go: extracting github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8
git.icod.de/dalu/socialthing/cmd imports
github.com/gin-gonic/gin/binding imports
github.com/ugorji/go/codec: ambiguous import: found 
github.com/ugorji/go/codec in multiple modules:
github.com/ugorji/go v1.1.4 
(/home/darko/go/pkg/mod/github.com/ugorji/go@v1.1.4/codec)
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 
(/home/darko/go/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181204163529-d75b2dcb6bc8)


What does that even mean?
Why?
How do I fix this?
How do I permanently disable go mod?
I don't want it, I don't need it.

build git.icod.de/dalu/socialthing: cannot load github.com/ugorji/go/codec: 
ambiguous import: found github.com/ugorji/go/codec in multiple modules:
github.com/ugorji/go v1.1.4 
(/home/darko/go/pkg/mod/github.com/ugorji/go@v1.1.4/codec)
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 
(/home/darko/go/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181204163529-d75b2dcb6bc8)

/wrist

-- 
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/db1df738-78fd-4ee0-933e-69ad25cb022e%40googlegroups.com.


Re: [go-nuts] Go+ replacement

2019-04-23 Thread Darko Luketic
But Twitter is a loose group of individuals, or does it have group 
functionality now? Everything is done via #channels last time I checked.
I honestly very rarely use it, too small sized posts, it's very chaotic and 
stuff you've seen just now is gone after a reload and can't be found again.
Also it's always so political and full of journalists, so hipster, all show 
no substance.
Anyhow what channels or "hashtags" do you subscribe to, or can you even 
subscribe to hashtags?

On Tuesday, April 23, 2019 at 4:52:14 PM UTC+2, David Riley wrote:
>
> On Apr 21, 2019, at 9:02 PM, icod...@gmail.com  wrote: 
> > 
> > I don't know about you but for me, even if there wasn't so much going 
> on, Google+ and the Go+ community was a source of info. 
> > 
> > Reddit is reddit, this whatever it is, is what it is, mewe can't 
> replace G+. 
> > Facebook just isn't the crowd. 
> > Xing and the like just aren't made to handle the task of staying 
> informed and people presenting their work. 
> > 
> > An essential source of information has disappeared. 
> > What is there to replace it? 
> > 
> > People would post links to youtube videos there, some were quite 
> interesting and some were fresh from the horses mouth about whatever 
> conferences or happenings. 
> > It's all gone now. 
> > 
> > Nuts is more of a "help I have a problem" thing. 
> > 
> > I know, Google+ had its own issues, the biggest was them forcing changes 
> onto their users no one wanted. 
> > As a result most people stopped using it and in the end it disappeared. 
> > 
> > G+ did fill a nieche, that of the enterpreteur who also wanted to be 
> entertained and catch news, stay up to date. 
> > 
> > I know this post is kind of pointless, since it won't change what is. 
> > But maybe something exists that I'm unaware of 
>
> I actually find that the Go community on Twitter fills a lot of those 
> roles for me fairly well. 
>
>
> - Dave 
>
>

-- 
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] A modular approach, plugins, lifecycle and wasm

2019-01-15 Thread Darko Luketic
I'm currently writing a forum, I've been doing that for a few months now.

You know how people have a plushi next to the they can talk to in order to 
develop ideas, this is my plushi.

And while writing I've been thinking of all the great forum software PHP 
has, vbulletin, phpbb to name the most prominent.
They have a plugin system.
They also have a lifecycle.

And then there is Drupal which is essentially a customizable content 
platform.

A plugin in Go can be both a literal plugin ( 
https://golang.org/pkg/plugin/ )
but also an interface that describes a "CMS plugin".
e.g.

type CMSplugin interface {
Register()
UnRegister()
// ...
}

Drupal has lifecycle hooks
e.g. https://api.drupal.org/api/drupal/includes%21module.inc/group/hooks/7.x

I'm not looking to clone Drupal, but take it more of as it being an 
inspiration.

I remember around 2000 modular C++ design was all the rage.
But what about Go? It has all the tools.

What would lifecycles be...?

Does this design principle even apply to a restful service since there is 
also the rendering part.
So one would have to create an "isomorphic" toolset.

Web assembly with Go apparently doesn't have the performance needed, from 
one blog post I've read.
But I guess I have to do my own research first, as always ;)
The intro to web assembly is really nice. However syscall/js is 
experimental without a stable api.

But even the renderer could be a module...
I don't know where to start. I feel like I'm trying to mix  tomatos with 
bananas.

Any input/feedback or ideas at all would be appreciated.

... some notes

A traditional webpage has
request
computation/processing
response

request hits middleware where the context carries values then finally reach 
a handler that does usually get data from a database based on the request 
parameters, then render a response, be it a html page or json output.

So we have
ProcessRequest
LoadDataFromDatabase
SaveDataToDatabase
RenderOutput

Only in our case the middleware is a plugin.

So we have following lifecycle hooks

BeforeProcessRequest
ProcessRequest
AfterProcessRequest

BeforeLoadDataFromDatabase
LoadDataFromDatabase
AfterLoadDataFromDatabase

BeforeSaveDataToDatabase
SaveDataToDatabase
AfterSaveDataToDatabase

BeforeRenderOutput
RenderOutput
AfterRenderOutput

So everything is a plugin

But there is more to be considered.
Routes/Routing.
And how do I know which plugin works for which handler?

So I'm guessing there need to be core plugins and handler plugins.

Core plugins..
I load my configuration from environment vars, from a config file, from 
input params.
I connect to a database and pass this to either repositories or the handler 
struct as a member.
I set up a logger
I set up routes that map to handlers
I run it

But, what if I want to use different DBs...
then I can define those in the configuration
So the configuration needs a certain layout

BeforeLoadPlugins
LoadPlugins
AfterLoadPlugins

BeforeLoadConfiguration
LoadConfiguration
AfterLoadConfiguration

BeforeConnectToDatabases
ConnectToDatabases
AfterConnectToDatabases

BeforeSetupLogger
SetupLogger
AfterSetupLogger

BeforeSetupRoutes
SetupRoutes
AfterSetupRoutes

BeforeRun
Run
AfterRun

What about making it event based?

EventHandler...
a struct with a channel of a struct
type Event struct {
Name string
Callback func(params ...interface{})
}
type EventHandler struct {
EventC <-chan Event
}

Sounds like a plan

-- 
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: json and interface unmarshalling

2018-12-14 Thread Darko Luketic
Of course after I ask my question I find the answer on my own.
It's always like this.

The solution is to change

type MessageRequest struct {
   Typestring  `json:"type"`
   Payload json.RawMessage `json:"payload"`
}


So the payload isn't unmarshalled.

Now, after the MessageRequest is unmarshalled I can check for the type and 
then

payload := new(model.ChatMessage)
if e := json.Unmarshal(m.Payload, payload); e != nil {
   logrus.Error(e)
   return
}



On Friday, December 14, 2018 at 8:17:25 PM UTC+1, Darko Luketic wrote:
>
> Hello,
>
> I'm sending messages over websocket.
> I have a "generic" MessageRequest and MessageResponse struct.
>
> type MessageRequest struct {
>Typestring  `json:"type"`
>Payload interface{} `json:"payload"`
> }
>
> type MessageResponse struct {
>Typestring  `json:"type"`
>Payload interface{} `json:"payload"`
> }
>
>
>
> I'm trying to unmarshall this.
>
> m := new(MessageRequest)
> if e := json.Unmarshal(msg, m); e != nil {
>logrus.Error(e)
>return
> }
>
>
> Then I switch by MessageRequest.Type to know what kind of message was sent 
> by the client.
>
> However, when I do something like
> payload, ok := m.Payload.(*MessageRequest)
> if !ok {
> //error
> }
>
> It isn't compatible to type *MessageRequest
> As a workaround I could imagine marshalling the interface again, then 
> unmarshalling into the correct message payload type (e.g. ChatMessage)
> But that is unnecessary overhead. However it beats marshalling into 
> map[string]interface and manually assigning values in terms of code 
> readability.
>
> tmp, e := json.Marshal(m.Payload)
> if e != nil {
>logrus.Error(e)
>return
> }
> payload := new(model.ChatMessage)
> if e := json.Unmarshal(tmp, payload); e != nil {
>logrus.Error(e)
>return
> }
>
>
>
> vs
>
> pmap, ok := m.Payload.(map[string]interface{})
> if !ok {
>logrus.Error("can not convert to map[string]interface{}")
>return
> }
> payload := new(model.ChatMessage)
> user := pmap["user"].(string)
> payload.User = user
>
> message := pmap["message"].(string)
> payload.Message = message
>
> tme := pmap["time"].(string)
> tmee, e := time.Parse(time.RFC3339, tme)
> if e != nil {
>logrus.Error("time parse error")
>return
> }
> payload.Time = tmee
>
>
> Is there a better solution to solve this?
>
>

-- 
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] json and interface unmarshalling

2018-12-14 Thread Darko Luketic
Hello,

I'm sending messages over websocket.
I have a "generic" MessageRequest and MessageResponse struct.

type MessageRequest struct {
   Typestring  `json:"type"`
   Payload interface{} `json:"payload"`
}

type MessageResponse struct {
   Typestring  `json:"type"`
   Payload interface{} `json:"payload"`
}



I'm trying to unmarshall this.

m := new(MessageRequest)
if e := json.Unmarshal(msg, m); e != nil {
   logrus.Error(e)
   return
}


Then I switch by MessageRequest.Type to know what kind of message was sent 
by the client.

However, when I do something like
payload, ok := m.Payload.(*MessageRequest)
if !ok {
//error
}

It isn't compatible to type *MessageRequest
As a workaround I could imagine marshalling the interface again, then 
unmarshalling into the correct message payload type (e.g. ChatMessage)
But that is unnecessary overhead. However it beats marshalling into 
map[string]interface and manually assigning values in terms of code 
readability.

tmp, e := json.Marshal(m.Payload)
if e != nil {
   logrus.Error(e)
   return
}
payload := new(model.ChatMessage)
if e := json.Unmarshal(tmp, payload); e != nil {
   logrus.Error(e)
   return
}



vs

pmap, ok := m.Payload.(map[string]interface{})
if !ok {
   logrus.Error("can not convert to map[string]interface{}")
   return
}
payload := new(model.ChatMessage)
user := pmap["user"].(string)
payload.User = user

message := pmap["message"].(string)
payload.Message = message

tme := pmap["time"].(string)
tmee, e := time.Parse(time.RFC3339, tme)
if e != nil {
   logrus.Error("time parse error")
   return
}
payload.Time = tmee


Is there a better solution to solve this?

-- 
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: ast Field's type

2018-04-17 Thread Darko Luketic
I solved it by experimenting.

*ast.Ident for the "string"
*ast.SelectExpr for the package type

Seems like there is no easier way.

On Tuesday, April 17, 2018 at 7:55:13 PM UTC+2, Darko Luketic wrote:
>
> Hi,
>
> I'm trying to parse a file (or rather more files, but let's keep it 
> simple).
>
> package models
>
> import "github.com/globalsign/mgo/bson"
>
> type Community struct {
>Id   bson.ObjectId `bson:"_id,omitempty" json:"id"`
>OwnerId  string`bson:"owner_id" json:"owner_id"`
>CategorySlug string`bson:"category_slug" json:"category_slug"`
>Name string`bson:"name" json:"name"`
>Description  string`bson:"description" json:"description"`
>Subdomainstring`bson:"subdomain" json:"subdomain"`
>Domain   string`bson:"domain" json:"domain"`
> }
>
>
> and I essentiall do
>
> ast.Inspect(v, func(node ast.Node) bool {
>switch n := node.(type) {
>case *ast.TypeSpec:
>   m.Name = n.Name.String()
>case *ast.Field:
>   fmt.Println("**0")
>   fmt.Println("IS_FIELD", n, "END")
>   fmt.Println(n.Names)
>   fmt.Printf("%+v\n", n.Type)
>   switch nn := n.Type.(type) {
>   default:
>  fmt.Printf("%+v", nn)
>   }
>   fmt.Println(n.Doc)
>   fmt.Println(n.Comment)
>   fmt.Printf("%+v\n", n.Tag)
>
>   fmt.Println("**1")
>
>default:
>   fmt.Println(n, "END")
>}
>return true
> })
>
>
>
> but you see, Id is type bson.ObjectId and the output of it is different 
> from it being a string
>
> &{X:bson Sel:ObjectId}
>
> where a string is just a string with "string" content, at least that's 
> what I assume.
>
> What type is "nn" here?
> How do I find that out short of trying all *ast.Types. 
> The doc just says 
>
> TypeExpr <https://golang.org/pkg/go/ast/#Expr>  // 
> field/method/parameter type
> but "Expr" is a generic term with a description of
> "All expression nodes implement the Expr interface."
> https://golang.org/pkg/go/ast/#Expr
>
> Well carefully browsing the documentation here I can somewhat guess from the 
> fields that 
> &{X:bson Sel:ObjectId} is a *ast.SelectorExpr
> https://golang.org/pkg/go/ast/#SelectorExpr
>
> but what is a plain field type?
>
> Is there a surefire method to find that out short of typechecking every 
> possible type?
>
>
>
>

-- 
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] ast Field's type

2018-04-17 Thread Darko Luketic
Hi,

I'm trying to parse a file (or rather more files, but let's keep it simple).

package models

import "github.com/globalsign/mgo/bson"

type Community struct {
   Id   bson.ObjectId `bson:"_id,omitempty" json:"id"`
   OwnerId  string`bson:"owner_id" json:"owner_id"`
   CategorySlug string`bson:"category_slug" json:"category_slug"`
   Name string`bson:"name" json:"name"`
   Description  string`bson:"description" json:"description"`
   Subdomainstring`bson:"subdomain" json:"subdomain"`
   Domain   string`bson:"domain" json:"domain"`
}


and I essentiall do

ast.Inspect(v, func(node ast.Node) bool {
   switch n := node.(type) {
   case *ast.TypeSpec:
  m.Name = n.Name.String()
   case *ast.Field:
  fmt.Println("**0")
  fmt.Println("IS_FIELD", n, "END")
  fmt.Println(n.Names)
  fmt.Printf("%+v\n", n.Type)
  switch nn := n.Type.(type) {
  default:
 fmt.Printf("%+v", nn)
  }
  fmt.Println(n.Doc)
  fmt.Println(n.Comment)
  fmt.Printf("%+v\n", n.Tag)

  fmt.Println("**1")

   default:
  fmt.Println(n, "END")
   }
   return true
})



but you see, Id is type bson.ObjectId and the output of it is different 
from it being a string

&{X:bson Sel:ObjectId}

where a string is just a string with "string" content, at least that's what 
I assume.

What type is "nn" here?
How do I find that out short of trying all *ast.Types. 
The doc just says 

TypeExpr   // 
field/method/parameter type
but "Expr" is a generic term with a description of
"All expression nodes implement the Expr interface."
https://golang.org/pkg/go/ast/#Expr

Well carefully browsing the documentation here I can somewhat guess from the 
fields that 
&{X:bson Sel:ObjectId} is a *ast.SelectorExpr
https://golang.org/pkg/go/ast/#SelectorExpr

but what is a plain field type?

Is there a surefire method to find that out short of typechecking every 
possible type?



-- 
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] math type algo question and Go's int size

2018-04-08 Thread Darko Luketic
Yeah I'm not a math wiz and the older I get the harder I find maths.
But sometimes you can't evade maths in programming.

So here's my question for math wizards.
Essentially, I'm trying to write an url shortener.
And I found this package I agree with (don't re-invent the wheel)
https://github.com/neptulon/shortid

It base64-encodes a random number of [bits that need to be dividable by 8] 
length.
Dividable by 8 because 1 char = 8 bits.

It generates an input+1/8 length result.

What I like is, get a count of all links in the db, easy.
But now the problem.

8bit = 64^2 possible results without overlapping., 2 characters (therefore 
64^2)
16bit = 64^3 etc
up to 64bit with would equal an uint64 value

My problem is computing the formula.
if link_count > number_bits/2 {
  number_bits++
}

but how do I find out the bits?
and make it future proof (yes even with the size of uint64)
aka I must not define ranges e.g. >=0 <=(64^2)/2
because I'm afraid the value would overflow in Go. (64^9)

I could
exponent := 2 // starts at 2 because bits = (exponent-1)*8
result := link_count / (64^exponent)
if result < 1.0 {
  number_bits = exponent-1
  if result < 0.5 {
good_to_generate = true
  } else {
exponent++
  }
}

but it would still probably overflow

However... MongoDB (my backing database), at least the mgo driver returns 
an int, which on 64bit machines is int64.
So there's my limit. Let's hope "int128" will be enough.

I guess I answered my own question. I'll still post it, because it took 
some time to write.

-- 
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: using gofmt "internally" to format a string, aka in memory go code formatter

2018-03-26 Thread Darko Luketic
Thank you everyone

On Monday, March 26, 2018 at 7:29:15 PM UTC+2, Darko Luketic wrote:
>
> How would I use something like gofmt to format a string in memory?
>
> I wouldn't want to write a temporary file then os.Exec gofmt and re-read 
> that file.
> There has to be a better way. Did anyone do anything like that before?
>

-- 
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] using gofmt "internally" to format a string, aka in memory go code formatter

2018-03-26 Thread Darko Luketic
How would I use something like gofmt to format a string in memory?

I wouldn't want to write a temporary file then os.Exec gofmt and re-read 
that file.
There has to be a better way. Did anyone do anything like that before?

-- 
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] net/http GET request with params

2017-12-11 Thread Darko Luketic
Hello,

I'm really puzzled.
I tried Set and Add. Request.Url.Query() is empty
Do I have to build the uri first before and then passing it to 
http.NewRequest?

func HybridFlow() {
   response_type := "code id_token"
   scope := "openid profile email"
   nonce := uniuri.New()
   state := uniuri.New()
   requri := "https://some_uri;
   client := http.DefaultClient
   client.Timeout = time.Second * 10
   req, e := http.NewRequest(http.MethodGet, requri, nil)
   if e != nil {
  log.Fatal(e)
   }
   req.URL.Query().Set("scope", scope)
   req.URL.Query().Set("response_type", response_type)
   req.URL.Query().Set("nonce", nonce)
   req.URL.Query().Set("state", state)
   req.URL.Query().Set("client_id", ClientID)
   req.URL.Query().Set("client_secret", ClientSecret)
   req.URL.Query().Set("redirect_uri", RedirectURI)

   fmt.Println("query", req.URL.Query())

   rsp, e := client.Do(req)
   if e != nil {
  log.Fatal(e)
   }
   fmt.Println(rsp)
   body, e := ioutil.ReadAll(rsp.Body)
   if e != nil {
  log.Fatal(e)
   }
   fmt.Printf("%s", body)
}

-- 
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: Generic service via interfaces...

2017-05-29 Thread Darko Luketic
Humm.. I wrote a reply but it seems it only reached Justin and not this 
group.
Also I have not received other replies via email.

Ok...

Ayan, no that's alright it was storage.UserModelInterface
and I know what you're all saying but I saw no other way to make them type 
agnostic and I'm a fan of explicitly calling things what they are 
especially when I'm experimenting.
And it's not really the point.

I tried Justin's idea or rather the idea that resulted because of Justin's 
reply
and
https://github.com/dalu/forum/tree/6bb47c27c606b30f91412b48b1af561abe0f5558/server/storage/mongo/service
it's not thread safe

because it operates on the passed instance of the concrete model.
In 
https://github.com/dalu/forum/blob/6bb47c27c606b30f91412b48b1af561abe0f5558/server/storage/mongo/service/user_test.go#L24
I initialize a service with a new user storage and a pointer to a 
(mongo)model.User
In 
https://github.com/dalu/forum/blob/6bb47c27c606b30f91412b48b1af561abe0f5558/server/storage/mongo/service/user.go#L21
I copy the pointer for the lack of better means to create a new copy, 
shallow copy (a := *b) doesn't work because it's an interface

So I think I'll just call it quits and go concrete up to the service level.
Yeah Egon ID is the lowest common denominator (that brainfart moment on 
reddit was me ;) ). And it would probably work but I'm not risking it for 
this one :)
For bson I can use the getter/setter interfaces but idk if there's 
something like it for other databases, so I'll just go abstract (or 
interface) on the service level.
And the storage/repository and model will be concrete.
UserService will be an interface
ThreadService will be an interface and so on
and there will be MongoUserService PostgresUserService and so on.
and implementing new databases will be a pain in the butt.
But that's Go for you :)

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


[go-nuts] Generic service via interfaces...

2017-05-28 Thread Darko Luketic
I'm stuck and I hoped it wouldn't come to that.

I wanted to have interfaces for various databases aka "I wanted to support 
multiple databases" (not debatable).
The idea was have ModelInterface (UserModelInterface, 
CategoryModelInterface etc) which would wrap the model with getters setters
StorageInterface which would CRUD the modelinterfaces
and finally services which would implement higher level and more convenient 
functions and use storage interfaces to store data.

Well up to the point where I started creating services everything went 
mostly smooth.
But I hoped I could keep the services database-agnostic.
However I can't.

https://github.com/dalu/forum/tree/f39df77f5003f71f08f473970b3df1fbd29a5a43

as you can see in line 19 and 20
https://github.com/dalu/forum/blob/f39df77f5003f71f08f473970b3df1fbd29a5a43/server/service/user.go#L19

when I use a concrete model.User (aka line 20) everything works without 
error.
but when I use var m storage.ModelInterface and then call a member function 
of the interface (SetName)
Go panics because nil pointer dereference

=== RUN   TestNewUserService
--- FAIL: TestNewUserService (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference 
[recovered]
panic: runtime error: invalid memory address or nil pointer 
dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x80 pc=0x5ba9f8]

goroutine 5 [running]:
testing.tRunner.func1(0xc420068b60)
/usr/lib/go/src/testing/testing.go:622 +0x29d
panic(0x5f1520, 0x721990)
/usr/lib/go/src/runtime/panic.go:489 +0x2cf
git.icod.de/dalu/forum/server/service.(*UserService).CreateUser(0xc420055f40, 
0x62f170, 0x8, 0x630677, 0xd, 0x62e844, 0x6, 0x7ffdb1d66ba1, 0xc420031f68)
/home/darko/go/src/git.icod.de/dalu/forum/server/service/user.go:19 
+0x28
git.icod.de/dalu/forum/server/service.TestNewUserService(0xc420068b60)

/home/darko/go/src/git.icod.de/dalu/forum/server/service/user_test.go:23 
+0x1f9
testing.tRunner(0xc420068b60, 0x63af98)
/usr/lib/go/src/testing/testing.go:657 +0x96
created by testing.(*T).Run
/usr/lib/go/src/testing/testing.go:697 +0x2ca
exit status 2
FAILgit.icod.de/dalu/forum/server/service   0.005s

However I don't know what the problem was that I had previously an 
interface *does have* allocated memory but not in the same way the concrete 
model that fits the interface does so they're not compatible, which lead me 
to some headaches.
So when an interface has memory allocated, why can't I use it as if it has 
memory allocated?

As it is right now I'll have to dump all the StorageInterface and 
ModelInterface interfaces because it doesn't make sense to use them since 
I'm bound to a specific model/db at the topmost level,which is "service".
"And this is why we can't have nice things".
Removing those would also lower the memory footprint when querying for 
multiple results (slices, find/readall).
It's sad, I really wanted to, but I can't.

So lesson learned:
- keep models the way they are, conrete for the expected database. A 
mongodb model is different from a pgsql model is different from a cassandra 
model
- storage/repository can be concrete and it should just do CRUD
- interface only at the top level, aka service
- there is no 1 fits all in Go

routes <> handler  service  storage/repository 
 model

effectively
MySQLUserService
MongoDBUserService
CassandraUserService
RethinkDBUserService
but
type UserService interface {
//...
}

Question, is there any sane way to solve it without throwing it all away? 
Hope dies last. Any trick to make it still work with interfaces on the 
service level without needing to create a concrete database bound instance 
of a model/struct?

-- 
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] Streaming EME mp3?

2017-01-03 Thread Darko Luketic
We have a site with many mp3 files.

And every now and then someone would have the smart idea to download our 
files and put them on Youtube for monetization purposes.

I'd like to stop that.
I read a bit about "Encrypted Media Extensions" aka browser drm.

But I'm not sure how that is done on the server side.

Has anyone played with this or has any experience with it?
How do you encrypt a mp3 file so it's able to be unencrypted in the browser 
and played via EME?

-- 
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.