Skip to content

Commit

Permalink
Merge pull request #32 from go-slide/feature/core/renaming-from-ferry…
Browse files Browse the repository at this point in the history
…-slide

renamed framework name
  • Loading branch information
saiumesh535 authored Jul 30, 2020
2 parents c5cda76 + 22c8344 commit 1c483a7
Show file tree
Hide file tree
Showing 18 changed files with 229 additions and 229 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 Ferry
Copyright (c) 2020 Slide

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# ferry-go
# slide-go

## Installation
```cmd
go get -u github.com/ferry-go/ferry
go get -u github.com/slide-go/slide
```
**Not Production Ready**

[![codecov](https://codecov.io/gh/ferry-go/ferry/branch/master/graph/badge.svg)](https://codecov.io/gh/ferry-go/ferry)
[![Go Report Card](https://goreportcard.com/badge/github.com/ferry-go/ferry)](https://goreportcard.com/report/github.com/ferry-go/ferry)
[![codecov](https://codecov.io/gh/slide-go/slide/branch/master/graph/badge.svg)](https://codecov.io/gh/slide-go/slide)
[![Go Report Card](https://goreportcard.com/badge/github.com/slide-go/slide)](https://goreportcard.com/report/github.com/slide-go/slide)

## Example

Expand All @@ -17,11 +17,11 @@ package main

import (
"fmt"
"github.com/ferry-go/ferry/middleware"
"github.com/slide-go/slide/middleware"
"log"
"net/http"

"github.com/ferry-go/ferry"
"github.com/slide-go/slide"

"github.com/go-playground/validator/v10"
)
Expand All @@ -34,36 +34,36 @@ type Login struct {

func main() {
validate := validator.New()
config := ferry.Config{
config := slide.Config{
Validator: validate,
}

app := ferry.InitServer(&config)
app := slide.InitServer(&config)

// compression middleware
app.Use(middleware.Compress())

// you can multiple middlewares also
app.Use(func(ctx *ferry.Ctx) error {
app.Use(func(ctx *slide.Ctx) error {
fmt.Println("this will run for all URL(s)")
return ctx.Next()
})

app.Get("/", func(ctx *ferry.Ctx) error {
app.Get("/", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})

// redirect to new url
app.Get("/redirect", func(ctx *ferry.Ctx) error {
app.Get("/redirect", func(ctx *slide.Ctx) error {
return ctx.Redirect(http.StatusTemporaryRedirect, "http://localhost:3000/static")
})

app.Get("/name/:name", func(ctx *ferry.Ctx) error {
app.Get("/name/:name", func(ctx *slide.Ctx) error {
name := ctx.GetParam("name")
return ctx.Send(http.StatusOK, fmt.Sprintf("hello, %s", name))
})

app.Post("/login", func(ctx *ferry.Ctx) error {
app.Post("/login", func(ctx *slide.Ctx) error {
login := Login{}
err := ctx.Bind(&login)
if err != nil {
Expand All @@ -77,11 +77,11 @@ func main() {
// Grouping your route
auth := app.Group("/auth")
// you can multiple middlewares also
auth.Use(func(ctx *ferry.Ctx) error {
auth.Use(func(ctx *slide.Ctx) error {
fmt.Println("this will run for all urls with /auth")
return ctx.Next()
})
auth.Get("/login", func(ctx *ferry.Ctx) error {
auth.Get("/login", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})

Expand All @@ -92,12 +92,12 @@ func main() {
app.ServeFile("/js", "static/login.js")

// Downloading file
app.Get("/download", func(ctx *ferry.Ctx) error {
app.Get("/download", func(ctx *slide.Ctx) error {
return ctx.SendAttachment("static/login.js", "login.js")
})

// uploading file
app.Post("/upload", func(ctx *ferry.Ctx) error {
app.Post("/upload", func(ctx *slide.Ctx) error {
return ctx.UploadFile("static/login.js", "login.js")
})

Expand All @@ -106,4 +106,4 @@ func main() {
```

## Benchmarks
![](https://i.ibb.co/TWdgzB8/ferry-benchmark.png)
![](https://i.ibb.co/TWdgzB8/slide-benchmark.png)
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ferry
package slide

import "github.com/go-playground/validator/v10"

// Config -- Configuration for ferry
// Config -- Configuration for slide
type Config struct {
Validator *validator.Validate
}
10 changes: 5 additions & 5 deletions context.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ferry
package slide

import (
"encoding/json"
Expand Down Expand Up @@ -117,11 +117,11 @@ func (ctx *Ctx) Bind(input interface{}) error {
//
// /name/:name
//
// /name/ferry
// /name/slide
//
// name := ctx.GetParam("name")
//
// name = ferry
// name = slide
//
func (ctx *Ctx) GetParam(name string) string {
return extractParamFromPath(ctx.routerPath, string(ctx.RequestCtx.Path()), name)
Expand Down Expand Up @@ -169,9 +169,9 @@ func (ctx *Ctx) ServeFile(filePath string) error {
return ctx.RequestCtx.Response.SendFile(filePath)
}

func getRouterContext(r *fasthttp.RequestCtx, ferry *Ferry) *Ctx {
func getRouterContext(r *fasthttp.RequestCtx, slide *Slide) *Ctx {
return &Ctx{
RequestCtx: r,
config: ferry.config,
config: slide.config,
}
}
46 changes: 23 additions & 23 deletions context_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ferry
package slide

import (
"bytes"
Expand All @@ -20,7 +20,7 @@ import (

type ContextSuite struct {
suite.Suite
Ferry *Ferry
Slide *Slide
}

type login struct {
Expand All @@ -33,20 +33,20 @@ func (suite *ContextSuite) SetupTest() {
Validator: validate,
}
app := InitServer(config)
suite.Ferry = app
suite.Slide = app
}

func (suite *ContextSuite) TestJsonResponse() {
path := "/hey"
response := map[string]string{
"user": "ferry",
"user": "slide",
}
suite.Ferry.Get(path, func(ctx *Ctx) error {
suite.Slide.Get(path, func(ctx *Ctx) error {
return ctx.JSON(http.StatusOK, response)
})
r, err := http.NewRequest(GET, "http://test"+path, nil)
if assert.Nil(suite.T(), err) {
res, err := testServer(r, suite.Ferry)
res, err := testServer(r, suite.Slide)
if assert.Nil(suite.T(), err) {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
Expand All @@ -66,15 +66,15 @@ func (suite *ContextSuite) TestJsonResponse() {
func (suite *ContextSuite) TestRedirect() {
path := "/hey"
redirectPath := "/redirect"
suite.Ferry.Get(path, func(ctx *Ctx) error {
suite.Slide.Get(path, func(ctx *Ctx) error {
return ctx.Redirect(http.StatusTemporaryRedirect, redirectPath)
})
suite.Ferry.Get(redirectPath, func(ctx *Ctx) error {
suite.Slide.Get(redirectPath, func(ctx *Ctx) error {
return ctx.Send(http.StatusOK, "redirected")
})
r, err := http.NewRequest(GET, "http://test"+path, nil)
if assert.Nil(suite.T(), err) {
res, err := testServer(r, suite.Ferry)
res, err := testServer(r, suite.Slide)
if assert.Nil(suite.T(), err) {
assert.Equal(suite.T(), res.StatusCode, http.StatusOK)
}
Expand All @@ -83,17 +83,17 @@ func (suite *ContextSuite) TestRedirect() {

func (suite *ContextSuite) TestBind() {
path := "/hey"
suite.Ferry.Post(path, func(ctx *Ctx) error {
suite.Slide.Post(path, func(ctx *Ctx) error {
body := login{}
_ = ctx.Bind(&body)
return ctx.JSON(http.StatusOK, body)
})
postBody, _ := json.Marshal(login{
Username: "Ferry",
Username: "Slide",
})
r, err := http.NewRequest(POST, "http://test"+path, strings.NewReader(string(postBody)))
if assert.Nil(suite.T(), err) {
res, err := testServer(r, suite.Ferry)
res, err := testServer(r, suite.Slide)
if assert.Nil(suite.T(), err) {
body, err := ioutil.ReadAll(res.Body)
if assert.Nil(suite.T(), err) {
Expand All @@ -106,16 +106,16 @@ func (suite *ContextSuite) TestBind() {

func (suite *ContextSuite) TestParamsAndQueryParams() {
path := "/hey/:name"
name := "ferry"
name := "slide"
paramsMap := map[string]string{
"name": name,
}
queryMap := map[string]string{
"key": "value",
"name": "ferry",
"name": "slide",
}
requestPath := fmt.Sprintf("/hey/%s?key=value&name=ferry", name)
suite.Ferry.Get(path, func(ctx *Ctx) error {
requestPath := fmt.Sprintf("/hey/%s?key=value&name=slide", name)
suite.Slide.Get(path, func(ctx *Ctx) error {
name := ctx.GetParam("name")
queryParamName := ctx.GetQueryParam("name")

Expand All @@ -130,20 +130,20 @@ func (suite *ContextSuite) TestParamsAndQueryParams() {
})
r, err := http.NewRequest(GET, "http://test"+requestPath, nil)
if assert.Nil(suite.T(), err) {
_, err := testServer(r, suite.Ferry)
_, err := testServer(r, suite.Slide)
assert.Nil(suite.T(), err)
}
}

func (suite *ContextSuite) TestServeFiles() {
path := "/hey"
filePath := "server.go"
suite.Ferry.Get(path, func(ctx *Ctx) error {
suite.Slide.Get(path, func(ctx *Ctx) error {
return ctx.ServeFile(filePath)
})
r, err := http.NewRequest(GET, "http://test"+path, nil)
if assert.Nil(suite.T(), err) {
_, err := testServer(r, suite.Ferry)
_, err := testServer(r, suite.Slide)
if assert.Nil(suite.T(), err) {
fileType, _ := getFileContentType(filePath)
assert.Equal(suite.T(), r.Header.Get(ContentType), fileType)
Expand All @@ -155,12 +155,12 @@ func (suite *ContextSuite) TestServeFiles() {
func (suite *ContextSuite) TestSendAttachment() {
path := "/hey"
filePath := "server.go"
suite.Ferry.Get(path, func(ctx *Ctx) error {
suite.Slide.Get(path, func(ctx *Ctx) error {
return ctx.SendAttachment(filePath, "server.go")
})
r, err := http.NewRequest(GET, "http://test"+path, nil)
if assert.Nil(suite.T(), err) {
resp, err := testServer(r, suite.Ferry)
resp, err := testServer(r, suite.Slide)
if assert.Nil(suite.T(), err) {
header := getAttachmentHeader("server.go")
assert.Equal(suite.T(), resp.Header.Get(ContentDeposition), header)
Expand Down Expand Up @@ -198,14 +198,14 @@ func (suite *ContextSuite) TestUploadFile() {
err = os.Mkdir(dirPath, os.ModeDir)
suite.NotNil(suite.T(), err)
}
suite.Ferry.Post(path, func(ctx *Ctx) error {
suite.Slide.Post(path, func(ctx *Ctx) error {
return ctx.UploadFile(uploadPath, fileName)
})
buffer, multiWriter := createMultipartFormData(suite, fileName, fileName)
r, err := http.NewRequest(POST, "http://test"+path, &buffer)
if assert.Nil(suite.T(), err) {
r.Header.Set("Content-Type", multiWriter.FormDataContentType())
_, err := testServer(r, suite.Ferry)
_, err := testServer(r, suite.Slide)
assert.Nil(suite.T(), err)
if assert.Nil(suite.T(), err) {
if _, pathError := os.Stat(uploadPath); pathError != nil {
Expand Down
Loading

0 comments on commit 1c483a7

Please sign in to comment.