PeernetOfficial / core

Core library. Use this to create a new Peernet application.
MIT License
36 stars 5 forks source link

[To Dicuss] Plan to increase usability of peernet #100

Open Akilan1999 opened 1 year ago

Akilan1999 commented 1 year ago

Discussion

The following issue is based on the development decision required for the abstraction issue (#99). When implementing the abstraction APIs most of the function and struct as referenced to the webapi package. In my opinion the future work related Peernet should use the abstraction package instead of the webapi package.

Webapi

The Webapi package should only be in-charge of accepting results and calling the abstracted functions and responding with the according results. Most of the Webapi helper functions should be migrated to the abstracted library. This will remove all possible import cycle compilation errors and reduce the size of the Webapi package and generalize all helper function required.

// Sample pseudo code for the Web API with abstractions used. 
func (w *Webapi)<function name>(r *request, w *writer) {
    reqObj := parseRequest(r) 
    resp := abstraction.<function name>(w.backend, <nil/"" (This is only used for direct interaction for preset defaults),reqObj)
    return render.resp 
}

// Example implementation
func (w *Webapi)Search(r *request, w *writer) {
    reqObj := parseRequest(r) 
    resp := abstraction.Search(w.backend, "",reqObj)
    return render.resp 
}

Abstractions

The abstraction library will be designed to take direct input as a parameter or optional parameters (if they are structs or more fine tuned requirements as requested from the Webapi). The following is an pseudo code example below:

// Example of pseudo code implementation 
func <function name>(b *core.backend,<single native supported datatype>, ...<reqobj>) <struct object pointer>{
      <abstraction implementation> 
       return <struct object pointer>
}

Possible steps to be taken: