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 todo | |
import "github.com/graphql-go/graphql" | |
// used for Todo Schema | |
var todoSchema = graphql.NewObject( | |
graphql.ObjectConfig{ | |
Name: "Todo", | |
Fields: graphql.Fields{ | |
"id": &graphql.Field{ |
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 todo | |
// used to store todos | |
var TodoItems = []Todo{} | |
// used to assign unique id to each todo | |
var count = 1 | |
// Here comes all the Queries |
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 todo | |
// Todo is a struct that represents a todo item | |
type Todo struct { | |
ID int `json:"id"` | |
Title string `json:"title"` | |
Completed bool `json:"completed"` | |
} |
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 ( | |
"log" | |
"sync" | |
"time" | |
) | |
// wg is a wait group | |
// it is used to wait for all go routines to finish |
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 ( | |
"log" | |
"time" | |
) | |
// addTwoNumbers adds two numbers together and prints the result | |
func addTwoNumbers(a int, b int) { | |
// sleep for a second to simulate a long running operation |
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 ( | |
"log" | |
"time" | |
) | |
// addTwoNumbers adds two numbers together and prints the result | |
func addTwoNumbers(a int, b int) { | |
// sleep for a second to simulate a long running operation |
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 ( | |
"log" | |
"runtime" | |
"runtime/pprof" | |
"sync" | |
"time" | |
) |
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 ( | |
"log" | |
"runtime" | |
"runtime/pprof" | |
"sync" | |
"time" | |
) |
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
from fastapi import FastAPI | |
from url_shortener import router | |
# Create the app | |
app = FastAPI() | |
# Add the router | |
app.include_router(router.url_shortener, prefix="/url-shortener") |
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
import secrets | |
import string | |
from fastapi import APIRouter | |
from url_shortener.models import CreateUrlShortener, CreateUrlShortenerResponse | |
from url_shortener.database import MockDBOperations | |
from starlette.responses import RedirectResponse | |
# Create the router | |
url_shortener = APIRouter() |