Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I want to understand what is Context in go gin , i see a lot of functions written which accept context as a parameter but dont see it passed anywhere or instantiated anywhere ? , can someone explain how it works
The gin Context is a structure that contains both the http.Request and the http.Response that a normal http.Handler would use, plus some useful methods and shortcuts to manipulate those.
The gin engine is responsible for the creation (and reuse) of those contexts, in the same manner as the http.Server is responsible for the creation of the http.Request objects a standard http.Handler would use.
The context is passed by the engine to its handlers, and it's your job to write those handlers and attach them to a router. A gin handler is any function that takes a gin.Context as its sole argument and doesn't return anything.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 10 months ago.
Improve this question
I try to fetch some data from api and store the data in a userdefault, then in another func to use the value in the userdefault. But sometimes when I try to get the value in the userdefault, it has not been fetched from api because of the poor internet, so how can I make sure I can get the data before I execute the second func.
Or do you have any solutions?
Thank you guys
There can always be conditions where you can fail a fetch. When you are executing your function that uses the data you were fetching you can first make sure there is any data at all, before manipulating it.
For slow internet specifically, you can check "retries" and retry mechanisms: example
One more thing, UserDefaults shouldn't be used for storing large data, it's typically used for storing some user preferences like colors, fonts, etc. (It's not encrypted - unsafe)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am looking to achieve something like this:
To have one input json request, which will encapsulate what to do than:
split that input into 3 or more sub-requests depending on json, like put in database
an agent will wake up since he is processing one part of that request, like putting data to some server
another agent will woke up since the request is for him too, he will like upload data to some other server
meanwhile another request could do state information about request whats part did executed and finished
Is Django + Celery good for this ?
Main goal is to with one request serve parts independently, so like when processing request when waiting for the server in one part of request will not ommiting other part of request which will be processed without any lag.
If your json contains all sub-requests and can be handled asynchronously, seems like this is a job for RxJava which can handle event based programs using observable sequences. Best to read the docs first to see if they fit your use case.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
This post was edited and submitted for review last year and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I am new to verilog and trying to figure out where the function can be defined/declared in verilog (like I know function can be defined in packages, what else?). Thanks in advance.
In Verilog, a function can be declared between
module and endmodule (ie in the current region of a module - inside a module, but outside an initial or always block)
generate and endgenerate
That's it.
In System-Verilog, a function can be declared between
module and endmodule
generate and endgenerate
and
class and endclass
interface and endinterface
checker and endchecker
package and endpackage
program and endprogram
and
outside a module / interface / checker / package / program
Probably, easiest way to declare and use function is like, declare all your functions in <module_function_pkg>.vh and include that to design verilog file.
Use it as #dave_59 said in comment.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I always see some classes that is named "ClassNameService", well what is the difference as logic? What is the goal of these service classes?
Generally speaking, there could be a hierarchy of domain objects, which are controlled by the services. If these domain objects are only data placeholders, with no behavior, then this is not true to object-oriented programming.
What we have here is what Martin Fowler would call the Anemic Domain Model.
More commonly, within OOP, a group of domain objects have behavior whose interactions form business logic. This logic, in turn, is encapsulated by the Service.
Such services are stateful, with their state being comprised of these domain objects.
Services may also be stateless and offer self-sufficient functionality.
Imagine, if you will, a very simple calculator API.
A HTTP request is sent to your application, which then uses the API to perform data extraction and some complex calculation. The application endpoint then returns a HTTP response containing the computed data as a SOAP/REST/etc. message.
Once the response is received, this should then be returned to the client that sent the original request.
You don't want to force your client to manually invoke the computation and transformation of the input. Instead, you want to simply offer them a service API which encapsulates this logic and returns to them the expected result.
For Spring applications, you have the Spring annotation #Service.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
If I have a business object with 50 fields, and I need to populate something like a drop down list or gridview with only 3 fields from the business object to allow quick browsing.
Is it best practice to load the fully populated BO then just grab the few required fields in your presentation layer ?
It seems inefficient to populate a collection of Bo's that size but the only other ways would seem to be to return partially populated BO's with just the fields you need for a particular UI which would be hard to manage if you have alot of similar UI requirements, or make a baseclass like MyBusinessObjectHeader that contains the fields then make MyBusinessObject inherit it and implement the rest of the fields but this would tie it your UI too much it seems.
Whats the best practice for this type of situation ?
I make a separate readonly list of readonly digest objects (or structs) that are lightweight and cannot be manipulated. The collection can be customized for whatever needs you might have as normal. Retrieval of a full object can be used by passing a "digest" object to a type conversion, or factory or constructor - whatever techniques you are using.
Note that this is an optimization which only happens when a collection of full-blown objects is simply getting too slow. It can easily be created at that point. Generally such classes are not created until necessary.
There are a lot of frameworks out there that do this sort of o/r mapping you're talking about.
You're trading a little more overhead for ease of use and robust configuration.
See Hibernate or NHibernate if you're using .net.