GithubHelp home page GithubHelp logo

Comments (12)

savsgio avatar savsgio commented on July 19, 2024

Hi,

You could server static files easily, you must set with https://godoc.org/github.com/savsgio/atreugo#Router.Static with this default configuration (IndexName == "index.html", GenerateIndexPages == true, AcceptByteRange == true)

You could make a PR to adds config support.

from atreugo.

savsgio avatar savsgio commented on July 19, 2024

Example:

config := &atreugo.Config{
		Host: "0.0.0.0",
		Port: 8000,
	}
	server := atreugo.New(config)

	server.Static("/static", "/var/www/html")

	err := server.ListenAndServe()
	if err != nil {
		panic(err)
	}

from atreugo.

imxxiv avatar imxxiv commented on July 19, 2024

I have seen godoc of atreugo about Static and ServeFile
I wish:

config := &atreugo.Config{
	Host: "0.0.0.0",
	Port: 8000,
	Compress: true,
	FS: &atreugo.FSConfig{
		IndexName: "index.m3u8",
		GenerateIndexPages: false, 
		AcceptByteRange: false,
	},
}
server := atreugo.New(config)

server.Static("/static", "/var/www/html")

err := server.ListenAndServe()
if err != nil {
	panic(err)
}

But now, I can only use the ugly code below to achieve:

fs := &fasthttp.FS{
    Root:               "/static",
    IndexNames:         []string{"index.m3u8"},
    GenerateIndexPages: false, 
    AcceptByteRange: false,
}
fsHandler := fs.NewRequestHandler()
server.Path("GET", "/", func(ctx *atreugo.RequestCtx) error {
	fsHandler(ctx.RequestCtx)
	return nil
})

Or use FileResponse to implement the requirements of IndexNames

from atreugo.

savsgio avatar savsgio commented on July 19, 2024

Ok, I will add it soon!

from atreugo.

savsgio avatar savsgio commented on July 19, 2024

But one question, Do you need to serve just index.m3u8 or everything there in root directory?

from atreugo.

savsgio avatar savsgio commented on July 19, 2024

Because you could use ServeFile, to serve just one file

myserver.ServeFile("/static/index.m3u8", "/var/www/html/index.m3u8")

If you use ctx.FileResponse(...), the file will download.

from atreugo.

imxxiv avatar imxxiv commented on July 19, 2024

Thank you very much for your response.
This project needs set IndexNames to index.m3u8. I just wish set FS value in one config, Because this allows me to quickly know the configuration of the server.
In the atreugo/consts.go , I see const network = "tcp4" , I need listen on ipv4 and ipv6 . Can you add a setting item in config to set tcp, tcp4, tcp6?

from atreugo.

imxxiv avatar imxxiv commented on July 19, 2024

I know atreugo from the fasthttp README.md page, Atreugo is a great web framework.
It's build on top of fasthttp, I hope atreugo helps developers set the parameters of fasthttp.
If the framework solidifies a part of the http parameter, Then developers can only make adjustments around the framework to meet project needs.

from atreugo.

savsgio avatar savsgio commented on July 19, 2024

Ok, i know it. I will try to add static files configuration soon.

About serve tcp4 or tcp6. By default, if you use myserver.ListenAndServe(), serves tcp4 connections, but if you need tcp6, you could create your own listener and use it with myserver.Serve(myListener) or myserver.ServeGracefully(myListener)
https://godoc.org/github.com/savsgio/atreugo#Atreugo.Serve.

But I think it's a good idea to add some setting to configure the kind of connections such as tcp, tcp4 or tcp6 easily

from atreugo.

savsgio avatar savsgio commented on July 19, 2024

I know atreugo from the fasthttp README.md page, Atreugo is a great web framework.
It's build on top of fasthttp, I hope atreugo helps developers set the parameters of fasthttp.
If the framework solidifies a part of the http parameter, Then developers can only make adjustments around the framework to meet project needs.

Thank you so much, my purpose it that.
So, I feel happy because the developers lets me know how i can improve the framework to makes their life easy hehe, and they and you use it.

from atreugo.

savsgio avatar savsgio commented on July 19, 2024

I've just added StaticCustom. Now you could serve files with your own configuration.

In a few days, i will release a new version 😄

from atreugo.

savsgio avatar savsgio commented on July 19, 2024

And you could set the kind of listener you want, with the Network option in configuration

from atreugo.

Related Issues (20)

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.