Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

January is Batteries-Included Go Framework inspired by Django. Designed to ease things up for fast development.

License

NotificationsYou must be signed in to change notification settings

akshanshgusain/january

Repository files navigation

January

January is Batteries-Included Go Framework inspired by Django. Designed to ease things up for fast development.

January DocsSupported Go versions


🎯 Features

  • 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

💡 Inspiration

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.

👻 What's New

  1. Built in Support for TailwindCSS.
  2. Supports DaisyUI-Components and Theme.
  3. Added Starter-APP right into the January-CLI

👾 WIP

  1. Build with January/January-recipes a repository of apps build with January framework
  2. Go January Docs:Documentation, coming soon!

⚙️ Installation

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!

⚡️ Quickstart

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!

🏢️ Project Structure

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

👀 Example Usage

Listed below are some of the common use-cases. If you want to see more code examples, please visit ourBuild With January repository

📖Generate Migration Files

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

Run migrations with thejanuary-cli. The following command will run the migration:

  1. Migrate Up: Run the latest up migration:
./january-cli migrate up
  1. Migrate Down: Run the latest down migration:
./january-cli migrate down
  1. Migrate Rest: Run all the down migrations and then run all the up migrations:
./january-cli migrate reset

📖Generate Model

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}

📖Create APIs

  1. Connect to yourPostgres database by supplying these values in the.env file

    DATABASE_TYPE=postgresDATABASE_HOST=localhostDATABASE_PORT=5432DATABASE_USER=postgres_useDATABASE_PASS=postgres_passwordDATABASE_NAME=postgres_dbDATABASE_SSL_MODE=disable
  2. Write your routes in theroutes.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)}
  3. 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)}

📆 Broken Features

  1. I will be removing the Jet Templating support, the standard library support for templating is decent.

📆 Upcoming Features

  1. MariaDB support
  2. Live-reloads
  3. Automatic Swagger Documentation
  4. File system support
  5. Support for Websockets, GraphQL and gRPC

Troubleshooting

🍎 Opening Unsigned Applications on macOS

Note: You may need to change permissions.

  1. Go to the Apple menu (🍎) in the top-left corner of your screen.
  2. Select "System Preferences" (or "System Settings" on newer macOS versions).
  3. Click on "Security & Privacy" (or just "Privacy & Security").
  4. 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).
  5. Click the "Open Anyway" button next to this message. You might need to click the lock icon and enter your password to make changes.
  6. A pop-up window will appear asking if you're sure you want to open the application. Click "Open" to run the app.
  7. 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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp