go-pkgz / rest Goto Github PK
View Code? Open in Web Editor NEWrest/http helpers
Home Page: https://go-pkgz.umputun.dev/rest/
License: MIT License
rest/http helpers
Home Page: https://go-pkgz.umputun.dev/rest/
License: MIT License
With #18 in place, one of the new options allows directory listing. Unfortunately, the one from stdlib is as ugly as hell and not customizable at all. It would be very nice to add the ability to make this list somewhat custom. Ideally, it should support some template with {{.Name}} {{.Size}} {{.DateTime}} and so on.
I don't see a direct way to achieve it and can think of a couple of hacks:
The goal is to remove the local lru cache implementation and replace it with go-pkgz/lcw package. LCW provides lru, ttl and redis caches. Recently added scache support should be fully compatible with rest's cache and migration supposed to be relatively painless
github.com/go-pkgz/rest v1.5.0
For some reason, SendErrorJSON
writes the wrong Content-Type.
rest.SendErrorJSON(w, r, nil, http.StatusNotFound, nil, "nothing to show")
Response:
HTTP/1.1 404 Not Found
Date: Thu, 07 May 2020 08:21:12 GMT
Content-Length: 28
Content-Type: text/plain; charset=utf-8
{"error":"nothing to show"}
Response code: 404 (Not Found); Time: 22ms; Content length: 28 bytes
Looks like w.Header().Set("Content-Type", "application/json; charset=utf-8")
should be called before w.WriteHeader(code)
.
As reported here the performance of the size limiter not that good for huge requests. This is unlikely even noticeable for a typical request, but in the case of uploading file chunks it is problematic
The current method uses LimitReader
to get the allowed part of the request and serves it from bytes buffer after the read. Actually, I'm not even sure why it's causing such a delay. I suspect some deficiency of the testing method, i.e. with size limiter in place the actual read of the data enforced, but maybe without it that read just skipped
Anyhow, for large limits the current approach may utilize a lot of memory, even if the performance problem is not real. Probably the better way to deal with this is to hijack the response writer and deal with the limit on the writer level
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.