Skip to content

Instantly share code, notes, and snippets.

@mayankchoubey
Created May 28, 2024 23:57
Show Gist options
  • Save mayankchoubey/939704ab10844eacbc632a6a0ef35f4d to your computer and use it in GitHub Desktop.
Save mayankchoubey/939704ab10844eacbc632a6a0ef35f4d to your computer and use it in GitHub Desktop.
Go vs Rust frameworks - Hello world
use actix_web::{get, App, HttpServer, Responder};
#[get("/")]
async fn index() -> impl Responder {
"Hello World!"
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(index))
.bind(("127.0.0.1", 3000))?
.run()
.await
}
use axum::{
routing::get,
Router,
};
#[tokio::main]
async fn main() {
let app = Router::new().route("/", get(|| async { "Hello World!" }));
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
axum::serve(listener, app).await.unwrap();
}
package main
import web "github.com/beego/beego/v2/server/web"
type MainController struct {
web.Controller
}
func (c *MainController) Get() {
c.Ctx.WriteString("Hello world!")
}
func main() {
web.Router("/", &MainController{})
web.Run()
}
package main
import (
"net/http"
"github.com/labstack/echo/v4"
)
func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello World!")
})
e.Start(":3000")
}
package main
import (
"github.com/gofiber/fiber/v2"
)
func main() {
app := fiber.New()
port := ":3000"
app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello World!")
})
app.Listen(port)
}
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.New()
r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello world!")
})
r.Run(":3000")
}
#[macro_use] extern crate rocket;
#[get("/")]
fn index() -> &'static str {
"Hello world!"
}
#[launch]
fn rocket() -> _ {
rocket::build().mount("/", routes![index])
}
use warp::Filter;
#[tokio::main]
async fn main() {
let routes = warp::path::end().map(|| "Hello World!");
warp::serve(routes)
.run(([127, 0, 0, 1], 3000))
.await;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment