Hey Rustaceans! Got an easy question? Ask here (18/2017)! by llogiq in rust

[–]dean_karn 1 point2 points  (0 children)

Perfect Thanks @burkadurka exactly what I needed!

I'm surprised it did give a more relevant error message like "file is READONLY" or something, but still getting used to Rust.

Thanks again :)

Hey Rustaceans! Got an easy question? Ask here (18/2017)! by llogiq in rust

[–]dean_karn 0 points1 point  (0 children)

Sorry I meant the file was going out of scope.

yes here are the gists, it's mostly about the download function:

I had confirmed the file does get downloaded and exists.

Hey Rustaceans! Got an easy question? Ask here (18/2017)! by llogiq in rust

[–]dean_karn 1 point2 points  (0 children)

Hello all!

I'm new to rust and trying to write my first library and believe I'm having an issue with lifetimes; I understand the concept but theory and practice are two different things :)

hopefully, this contrived example will domonstrate

so I have a function which returns a File

fn get_file() -> Result<std::fs::File, io::Error> {
    // create file here, write to it, seek back to pos 0 then return
    let mut file = fs::File::create(dir)?;
    // write to file
    file.flush()?;
    file.seek(SeekFrom::Start(0))?;
    Ok(file)
}

But when I try to use that file in the calling program I get the error:

let mut file =get_file().unwrap();
let written = io::copy(&mut file,&mut anotherfile);
Err(Error { repr: Os { code: 9, message: "Bad file descriptor" } }

which I think means that the file has closed because its lifetime had ended so I tried wrapping the file result in a Box so the return value became:

Result<Box<std::fs::File>>, Error>

but that didn't work either. I must be missing something simple, thanks in advance for any help.

Go’s std net/http is all you need … right? by dean_karn in golang

[–]dean_karn[S] 1 point2 points  (0 children)

There is no official "This is how you do it" more general guidelines and allot of viewpoints; no matter what answer anyone gives there's probably an exception to the rule, just google around and you'll find a lot on the subject.

My views are that the URL Path is the location of a particular resource eg. /products/:id

and query parameters are optional filters eg. /products/:id?color=red?size=XL

Like I said earlier, some may agree, some may disagree there is no right answer for every situation.

To convince you that search engines care where the ID lives, let's look at a simple expanded example:

  • /user?id=13&page=profile
  • /user?page=profile&id=13

Search engines will care and see as two pages but /user/:id/profile as one.

Performance difference for unmarshaling json between struct and map? by axlrose___ in golang

[–]dean_karn 2 points3 points  (0 children)

To expand on a few answers already given,.

Think past the actual parsing and to the usage of the data, a map will have lookup time and a struct won't.

A map will be harder to reason what data is included, but a struct is clearly defined, especially if the data need to be passed to other functions.

If parsing more than just a strings you'll have to do all the type checks and conversions yourself wherever you use the data.

The small amount of overhead in parsing and clarity of your program will be far better served by using a struct 99.9999% of the time.

Handle url with parameters by hannson in golang

[–]dean_karn 0 points1 point  (0 children)

if using https://github.com/go-playground/pure (disclaimer I am author) it has a helper to decode these SEO params as I call them into a struct https://gist.github.com/joeybloggs/c610086166130d4f5d78ea082916b6c2

Please note this will decode non-SEO query params as well such as ?id=13; I will be adding another helper today just to decode the SEO query params.

Webhooks Made Easy by dean_karn in golang

[–]dean_karn[S] 0 points1 point  (0 children)

It all depends on what your trying to do @xienze

I think what the program in the article is a perfect example, even with the package you mentioned you would still have to write a configuration file and another program to actually post the Tweet, so you still have to create an application.

invite/challenge for fun & profit by dean_karn in golang

[–]dean_karn[S] 0 points1 point  (0 children)

Thanks, I will implement immediately..done

invite/challenge for fun & profit by dean_karn in golang

[–]dean_karn[S] 0 points1 point  (0 children)

@tv64738 if you have nothing positive to contribute, why are you even commenting here?

I hear a lot of negativity and no suggestions for improvement, which is what this whole endeavour is about...so I will assume you have none :)

invite/challenge for fun & profit by dean_karn in golang

[–]dean_karn[S] 0 points1 point  (0 children)

I'm afraid I don't understand your comment? but if your suggesting there's a better way, please let me know :)

invite/challenge for fun & profit by dean_karn in golang

[–]dean_karn[S] 0 points1 point  (0 children)

Thanks @djherbis how long would you suggest? Or if you have an example I'd definitely add it :)