Created
May 28, 2024 23:57
-
-
Save mayankchoubey/939704ab10844eacbc632a6a0ef35f4d to your computer and use it in GitHub Desktop.
Go vs Rust frameworks - Hello world
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] extern crate rocket; | |
#[get("/")] | |
fn index() -> &'static str { | |
"Hello world!" | |
} | |
#[launch] | |
fn rocket() -> _ { | |
rocket::build().mount("/", routes![index]) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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