- Notifications
You must be signed in to change notification settings - Fork1
January is Batteries-Included Go Framework inspired by Django. Designed to ease things up for fast development.
License
akshanshgusain/january
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
January is Batteries-Included Go Framework inspired by Django. Designed to ease things up for fast development.
Docs:https://gojanuary.akshanshgusain.com/
Website:https://gojanuary.framer.website/
- Robust routing
- Serve static files
- Easy access to multiple databases
- Complete user authentication
- Database migrations
- Session support
- Template engines
- Generate handlers
- Middleware support
- Form Validation
- CSRF protection
- Encryption
- Multiple Caching backends
When teams at my organization began transitioning from Python, Node.js, and PHP to Go, we encountered a new challenge: as each developer utilized different libraries, standards, and frameworks, interoperability between teams became increasingly problematic. The January Web Framework was conceived with a "batteries-included" approach, enabling teams to swiftly integrate into the Go ecosystem while adhering to consistent standards across the organization.
- Built in Support for TailwindCSS.
- Supports DaisyUI-Components and Theme.
- Added Starter-APP right into the January-CLI
- Build with January/January-recipes a repository of apps build with January framework
- Go January Docs:Documentation, coming soon!
January requiresGo version1.18
orhigher to run. If you need to install or upgrade Go, visit theofficial Go download page.
To start setting up your project download theJanuary-CLI toolfrom hereJanuary-CLI
Problem runningJanuary-CLI?
or,
Homebrew installation: coming soon!
Here is a basic example to create a simple web app withJanuary-CLI:
./january-cli new github.com/your_username/your-repository_name
This command creates a new project directory namedyour-repository-name.After creating the project move the CLI to the project directory :
mv ./january-cli ./your-repository-name
and cd into the project directory:
cd your-repository-name/
The app comes bundled with a Makefile(currently only support macOS). Run the web app running:
make startBuilding January...January built!Starting January...January started!INFO2024/09/14 10:53:20 load session calledINFO2024/09/14 10:53:20 Starting January server at http://127.0.0.1:9095/INFO2024/09/14 10:53:20 Quit the server with control+c
Visithttp://localhost:9095 in your browser to the Home page. You can run themake stop
command to stop the web server.
make stopStopping January...Stopped January!
your-repository-name/│├── data/│ └── models.go│├── database/│ └── docker-compsoe.yaml│├── handlers/│ ├── handlers.go│ └── handlerHelper.go│├── middleware/│ └── middleware.go│├── migartions/│├── public/│ ├── ico/│ └── images/│├── views/│ ├── layouts/│ └── home.jet│├── .gitignore├── Makefile├── go.mod├── init.january.go├── januaryAppHelper.go├── main.go└── README.md└── routes.go
Listed below are some of the common use-cases. If you want to see more code examples, please visit ourBuild With January repository
Create migration file using thejanuary-cli. The following command will create two migration files:.up.sql and.down.sql in the
./january-cli make migration<migartion-name>
Run migrations with thejanuary-cli. The following command will run the migration:
- Migrate Up: Run the latest up migration:
./january-cli migrate up
- Migrate Down: Run the latest down migration:
./january-cli migrate down
- Migrate Rest: Run all the down migrations and then run all the up migrations:
./january-cli migrate reset
Create a model withjanuary-cli. The following command will create amodel-name.go
file in the data directory:
./january-cli make model<model-name>
By default the Models are generate withUpper DAL to access the Database. After generating themodelname.go
it needs to me added to theModel struct in thedata/models.go
.
vardb*sql.DBvarupper db2.SessiontypeModelsstruct {// any models inserted here (and in the new function)// are easily accessible throughout the entire applicationModelNamesModelName// <---- your Model(s)}funcNew(databasePool*sql.DB)Models {db=databasePoolswitchos.Getenv("DATABASE_TYPE") {case"mysql","mariadb":upper,_=mysql.New(databasePool)case"postgres","postgresql":upper,_=postgresql.New(databasePool)default:// do nothing}returnModels{ModelNames:ModelName{},}}
Now, your models are ready to use. The Models come with pre-build CRUD methods:
// ModelName structtypeModelNamestruct {IDint`db:"id,omitempty"`CreatedAt time.Time`db:"created_at"`UpdatedAt time.Time`db:"updated_at"`}// Table returns the table namefunc (t*ModelName)Table()string {return"modelnames"}// GetAll gets all records from the database, using upperfunc (t*ModelName)GetAll(condition up.Cond) ([]*ModelName,error) {collection:=upper.Collection(t.Table())varall []*ModelNameres:=collection.Find(condition)err:=res.All(&all)iferr!=nil {returnnil,err }returnall,err}// Get gets one record from the database, by id, using upperfunc (t*ModelName)Get(idint) (*ModelName,error) {varoneModelNamecollection:=upper.Collection(t.Table())res:=collection.Find(up.Cond{"id":id})err:=res.One(&one)iferr!=nil {returnnil,err }return&one,nil}// Update updates a record in the database, using upperfunc (t*ModelName)Update(mModelName)error {m.UpdatedAt=time.Now()collection:=upper.Collection(t.Table())res:=collection.Find(m.ID)err:=res.Update(&m)iferr!=nil {returnerr }returnnil}// Delete deletes a record from the database by id, using upperfunc (t*ModelName)Delete(idint)error {collection:=upper.Collection(t.Table())res:=collection.Find(id)err:=res.Delete()iferr!=nil {returnerr }returnnil}// Insert inserts a model into the database, using upperfunc (t*ModelName)Insert(mModelName) (int,error) {m.CreatedAt=time.Now()m.UpdatedAt=time.Now()collection:=upper.Collection(t.Table())res,err:=collection.Insert(m)iferr!=nil {return0,err }id:=getInsertID(res.ID())returnid,nil}// Builder is an example of using upper's sql builderfunc (t*ModelName)Builder(idint) ([]*ModelName,error) {collection:=upper.Collection(t.Table())varresult []*ModelNameerr:=collection.Session().SQL().SelectFrom(t.Table()).Where("id > ?",id).OrderBy("id").All(&result)iferr!=nil {returnnil,err }returnresult,nil}
Connect to yourPostgres database by supplying these values in the
.env
fileDATABASE_TYPE=postgresDATABASE_HOST=localhostDATABASE_PORT=5432DATABASE_USER=postgres_useDATABASE_PASS=postgres_passwordDATABASE_NAME=postgres_dbDATABASE_SSL_MODE=disable
Write your routes in the
routes.go
:func (a*application)routes()*chi.Mux {// GETa.get("/api/your-get-route",a.Handlers.GetHandler)// POSTa.post("/api/your-post-route",a.Handlers.PostHandler)// PUTa.put("/api/your-put-route",a.Handlers.PutHandler)// PATCHa.patch("/api/your-patch-route",a.Handlers.PatchHandler)// DELETEa.delete("/api/your-delete-route",a.Handlers.DeleteHandler)}
Create aHandler and write your business login:Create a handler using thejanuary-cli:
./january-cli make handler<your-handler-name>
The above command will create a handler named:
your-handler-name.go
in thehandlers directory.func (h*Handlers)GetHandler(w http.ResponseWriter,r*http.Request) {// Get path parameterpathParamVar:=chi.URLParam(r,"pathParamVar")// Get query parametersqueryParamVar:=r.URL.Query().Get("queryParamVar")// Business Logic goes here:...// declare return response structvarrespstruct {Errorbool`json:"error"`Messagestring`json:"message"`Valuestring`json:"value"` }resp.Error=falseresp.Message="Success"resp.Value=fromCache.(string)_=h.App.WriteJson(w,http.StatusOk,resp)}
- I will be removing the Jet Templating support, the standard library support for templating is decent.
- MariaDB support
- Live-reloads
- Automatic Swagger Documentation
- File system support
- Support for Websockets, GraphQL and gRPC
Note: You may need to change permissions.
- Go to the Apple menu (🍎) in the top-left corner of your screen.
- Select "System Preferences" (or "System Settings" on newer macOS versions).
- Click on "Security & Privacy" (or just "Privacy & Security").
- In the "General" tab, look for a message near the bottom that says "january-cli was blocked from use because it is not from an identified developer" (if you don't see this message, try to open the app again).
- Click the "Open Anyway" button next to this message. You might need to click the lock icon and enter your password to make changes.
- A pop-up window will appear asking if you're sure you want to open the application. Click "Open" to run the app.
- The app should now open, and macOS will remember your choice, allowing you to open the app normally in the future.
Alternative Method: Using Terminal:
xattr -d com.apple.quarantine /path/to/downloaded/exectable/january-cli
About
January is Batteries-Included Go Framework inspired by Django. Designed to ease things up for fast development.
Topics
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.