pitr / gig Goto Github PK
View Code? Open in Web Editor NEWGemini framework
License: MIT License
Gemini framework
License: MIT License
In the README you have an example about how to handle subdomains.
g.Handle("/*", func(c gig.Context) error {
app := apps[c.URL().Host]
if app == nil {
return gig.ErrNotFound
} else {
return app.ServeGemini(c)
}
})
The issue is, that app.ServeGemini
doesn't return anything, so this code will not compile.
Also, when app.ServeGemini(c)
is run and Handle just does a return nil
it will lead to a Stack overflow error if a URL is requested where no handler is registered for.
[gig-debug] ⇨ gemini server started on [::]:1965
time="2021-02-12T12:24:28+01:00" path=/ status=20 duration=0.03
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc022960430 stack=[0xc022960000, 0xc042960000]
fatal error: stack overflow
I think that there should be a separate function which is used to forward requests and which returns an error object which can be used by gig.HandleFunc.
See above.
g.Handle("/*", func(c gig.Context) error {
app := apps[c.URL().Host]
if app == nil {
return gig.ErrNotFound
}
app.ServeGemini(c)
return nil
})
Then make a request to a valid hostname but a URL without a handler.
func main() {
apps := map[string]*gig.Gig{}
// gemini.tunerapp.org
tu := tunerapp.App(true)
apps["gemini.tunerapp.org"] = tu
pa := paste.App()
apps["localhost"] = pa
g := gig.New()
g.Renderer = &templatesType{
templates: template.Must(template.New("index").Funcs(helpers).ParseGlob("templates/*.tmpl")),
}
g.Handle("/*", func(c gig.Context) error {
app := apps[c.URL().Host]
if app == nil {
return gig.ErrNotFound
}
app.ServeGemini(c)
return nil
})
log.Fatal(g.Run("cert.pem", "key.rsa"))
}
github.com/pitr/gig v0.9.7
I'm posting this issue just to make it know that improper TLS close is an issue in Geminispace, in case you might need to make sure gig does this properly.
It doesn't look like there's any way to specify a domain name when running Gig, it'd be nice to be able to do that. And then to have multi-host support, so certain paths can apply only to one host, while other paths do the other. Similar to CompositeApplication
in Jetforce.
It'd be cool to have basic Titan support. Titan is a complementary protocol to gemini that allows for upload only.
It uses the same port as gemini, but URLs use the "titan://" scheme. The URLs consist of a path with parameters delimited by semicolons (;
), with 3 different parameters, an optional token
(kinda like a password, not used for authorization, but rather to prevent bots and spam), a requied size
(in bytes) of file to be uploaded, and a required mime
parameter (mimetype). After that, then there's a \r\n
, followed by the data of the given size.
It also supports Client Certificates.
If the given data is of the wrong size, "59 Meta text" is sent. Otherwise, nothing is sent back, afaik (I could be wrong about this).
Here's the main page for the protocol: https://communitywiki.org/wiki/Titan
You can see a server implementation here: https://alexschroeder.ch/cgit/phoebe/tree/script/phoebe
And for the client: https://alexschroeder.ch/cgit/phoebe/tree/script/titan
Even just some way to hook into Gig to just get all requests that use the titan://
scheme and do my own stuff would be useful. But, if it used some of Gig's features, like routes, that would be cool too :)
The following method of serving static file
g.Static("/test.txt", "content/test.txt")
does not seem to work.
Server running on localhost. When client requests gemini://localhost/test.txt
, the server shall return the content of the text file located at content/test.txt
. The directory structure used is as follows:
--$GOPATH (dir)
|--src (dir)
|--gig_server (dir)
|--content (dir)
| |--test.txt
| |--imgs (dir)
| |--tuxedo_cat.jpg
|--main.go
|--go.mod
|--gig_server (executable)
|--my.crt
|--my.key
The server returns "not found", and logs the following
time="2021-06-18T06:09:03+00:00" path=/test.txt status=51 duration=0.06 error=Not Found
As described above.
content of main.go:
package main
import "github.com/pitr/gig"
func main() {
g := gig.Default()
g.Static("/test.txt", "content/test.txt")
g.Run("my.crt", "my.key")
}
content of test.txt:
Come find me!
go version go1.16.5 darwin/amd64.
gig version 0.9.8
When the "static file" designated is a directory, it works fine. e.g.,
g.Static("/imgs", "content/imgs")
works when client requests gemini://localhost/imgs/tuxedo_cat.jpg
.
Unhandled errors can be frustrating.
To solve it, just add
err := g.Run("my.crt", "my.key")
if err != nil { panic(err) }
to samples in README.md.
Feature request.
Gig looks great, nice work! I was wondering if reverse-proxying is on your roadmap, so all requests under a certain route or whatever is sent to a different Gemini server.
Context interface Set function signature is
Set(key string, val interface{})
that signature is not safe for client level code to use.
For example, library uses keyword "subject" and this keyword will collide if client level code will use "subject" as well.
Standard GO context
will not suffer from this issue if used correctly, because context.WithValue
uses interface for the key.
The proper use is demonstrated here: https://stackoverflow.com/questions/39946583/how-to-pass-context-in-golang-request-to-middleware.
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.