Giter Site home page Giter Site logo

Comments (11)

adelowo avatar adelowo commented on May 24, 2024 1
  • While what you are proposing works, i just like to stay too close to holy http.Handler interface..

  • I tried the ORM some time ago, didn't feel natural.. Plain sql for me is the way to go.

from realworld-starter-kit.

adelowo avatar adelowo commented on May 24, 2024 1

A fork it shall be... Should get that done in a couple hours

from realworld-starter-kit.

adelowo avatar adelowo commented on May 24, 2024 1

Ok, i found out i already have something like this..

You might want to look into it

Database => https://github.com/adelowo/reblog/tree/master/models (plus mocks)
Handlers => https://github.com/adelowo/reblog/tree/master/handler

https://github.com/adelowo/reblog/blob/master/main.go#L24

from realworld-starter-kit.

JackyChiu avatar JackyChiu commented on May 24, 2024 1

Yep I've switch it using DI!

from realworld-starter-kit.

adelowo avatar adelowo commented on May 24, 2024
  • DI would be preferable since it would make the code much more testable..... Plus it can also work as the application context pool

This could change to

func RegisterUser(db *SqlxBlah) error {
    return func (w http.ResponseWriter, h *http.Request) {
     //old code
   }
}
  • Sqlx would be more than enough though .

from realworld-starter-kit.

JackyChiu avatar JackyChiu commented on May 24, 2024

@adelowo yeah I definitely agree that DI was the way to go, I'll look into this approach!

For the example you posted, would you need to change it to this?

func RegisterUser(db *SqlxBlah, w http.ResponseWriter, h *http.Request) error {
    return func (w http.ResponseWriter, h *http.Request) {
     //old code
   }
}

How do you feel about the ORM? I started off with that just to get something up

from realworld-starter-kit.

adelowo avatar adelowo commented on May 24, 2024

I should be able to help out on a couple things though

from realworld-starter-kit.

JackyChiu avatar JackyChiu commented on May 24, 2024

@adelowo sorry I just wasn't too sure what you were saying but I think I see it now for the http.handler!

Yeah if you could show an example without the ORM I'd really appreciate it! And feel free to contribute to any part 😄

from realworld-starter-kit.

adelowo avatar adelowo commented on May 24, 2024

Can i pull a fork of this showing that ? or how do you want me to "show the example" ?

from realworld-starter-kit.

JackyChiu avatar JackyChiu commented on May 24, 2024

Can i pull a fork of this showing that ? or how do you want me to "show the example" ?

Yeah a fork, a gist, or whatever works 😁

from realworld-starter-kit.

qwo avatar qwo commented on May 24, 2024

I agree with the DI approach. This article does a good job showing a few approach.
http://www.alexedwards.net/blog/organising-database-access

from realworld-starter-kit.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.