?? ????? Twilio? ?? OTP ?? ??, ???? ???? ?????? OTP ?? ???, ??? ?? ?? ?? ??? ??? ?? ??? ?????.
Twilio? OTP ???
Twilio ??? API? ???? OTP? ??? ?? ??? ??? ????.
func (app *application) sendOTPViaTwilio(otp, phoneNumber string) error { client := twilio.NewRestClientWithParams(twilio.ClientParams{ Username: os.Getenv("TWILIO_SID"), Password: os.Getenv("TWILIO_API_KEY"), }) params := &api.CreateMessageParams{} params.SetBody(fmt.Sprintf( "Thank you for choosing Cheershare! Your one-time password is %v.", otp, )) params.SetFrom(os.Getenv("TWILIO_PHONE_NUMBER")) params.SetTo(fmt.Sprintf("+91%v", phoneNumber)) const maxRetries = 3 var lastErr error for attempt := 1; attempt <= maxRetries; attempt++ { resp, err := client.SendSms(params) if err == nil { app.logger.Printf("Message SID: %s", resp.Sid) return nil } lastErr = err time.Sleep(time.Duration(attempt) * 100 * time.Millisecond) } return fmt.Errorf("failed to send OTP after %d retries: %w", maxRetries, lastErr) }
? ??? Twilio? Go SDK? ???? ???? ????. from
??? ?? ??? Twilio ?????. ???? ?? ??? ????? ???? ????.
???? ??? ??? OTP ??
???? OTP ??? ?? ??? ??????. ? ????? ???? ???? OTP ??? ??? ???? ?? ?????. application
???? ?????????:
type application struct { wg sync.WaitGroup config config models data.Models logger *log.Logger cache *redis.Client }
??? ???? ????? ?? ??? ??????.
func (app *application) background(fn func()) { app.wg.Add(1) go func() { defer app.wg.Done() defer func() { if err := recover(); err != nil { app.logger.Printf("Error in background function: %v\n", err) } }() fn() }() }
sync.WaitGroup
? ???? ???? ???? ?? ?? ????? ?????.
?????? ?? ???
??? ??? ???? ?? ? ?????? ???? ?????.
-- 000002_create-token.up.sql CREATE TABLE IF NOT EXISTS tokens ( hash bytea PRIMARY KEY, user_id bigint NOT NULL REFERENCES users ON DELETE CASCADE, expiry timestamp(0) with time zone NOT NULL, scope text NOT NULL ); -- 000002_create-token.down.sql DROP TABLE IF EXISTS tokens;
? ????? ??? ??, ??? ID, ?? ?? ? ?? ??? ?????. ?????? ??????? migrate
? ???? ?????.
?? ?? ? ??
data/models.go
???? ?? ??, ?? ? ?? ??? ???? ????.
// ... (other imports) ... package data // ... (other code) ... func generateToken(userId int64, ttl time.Duration, scope string) (*Token, error) { // ... (token generation logic) ... } func (m TokenModel) Insert(token *Token) error { // ... (database insertion logic) ... } func (m TokenModel) DeleteAllForUser(scope string, userID int64) error { // ... (database deletion logic) ... } func (m TokenModel) New(userId int64, ttl time.Duration, scope string) (*Token, error) { // ... (token creation and insertion logic) ... }
? ??? ?? ??, ?? ? ?????? ?? ??? ?????. New
??? ??? ??? ???? ?????.
?? ??? ????
cmd/api/user.go
??? ?? ???? OTP ?? ?? ? ??? ????? ???????.
// ... (other functions) ... func (app *application) handleUserSignupAndVerification(w http.ResponseWriter, r *http.Request) { // ... (input parsing and validation) ... // ... (OTP generation and sending logic) ... // ... (OTP verification logic) ... // ... (user creation or retrieval) ... token, err := app.generateTokenForUser(user.ID) if err != nil { // ... (error handling) ... } // ... (success response with token) ... }
?? ?? ??? ?? ??? ?????.
???? ???
? ?? ???? ??? recoverPanic
, authenticate
? requireAuthenticatedUser
? ?? ? ?? ??? ?????. ?? ?? ???? ??? ?? ??? ???? ?????. ???? ?? ??(contextSetUser
? contextGetUser
)? ?? ???? ??? ??? ???? ???? ???? ? ?????.
?? ???? ??? ????? ???? ???, ????? requireAuthenticatedUser
? ???? ??? ???? ??? ?????. ?? ?? ???? ?? ???, ???? ?? ? ??? ??? ?????. ?? ??? GitHub?? ??? ? ????.
? ??? Go? ???? OTP ?? ?? ?? ??: 3?? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











GO? ????? ????? ??? ????? ??????. ?? ??? ?? ?????. 1. ? ??? ?? : Linux ????? ?? ??? ?????? ??? ??? ? ????. 2. ?? ??? ??? ?? ???? ???? ?? ??? ????? ?? ??? ?? ?? ??? ?? ??? ? ? ????. 3. ?? ?? ???? ?? : ?? ????? ??? ??? ?? ??? ??? ???? ??????. 4. ??? ?? ??? : ??? ???? ????? ?? ?????? ? ???? ? ? ??? ??? ? ??? ?????. ??? ??? CLI ??, ???? ??? ? ?? ????? ????? ????? ????? ?? ??? ??? ???? ????? ???? ??? ?????.

GO?? ?? ??? ???? MAKE ??? ?? ?? ?? ? ??????. ?? ??? ???? ??? ??? ???? ?? ? ???? ?? ? ?? ??? ???? ?? ? ???? ??? ??? ? ????. ?? ??, ch : = make (Chanint, 10)? ?? 10 ?? ?? ?? ??? ??? ?? ??? ????. ???? ?? ??? ??, ??? ???? ?? ???? ??? ???? ???? ?? ? ??? ??? ????? ?????. ??? ??? ?, ?? : 1. ?? ??? ??? ??? ?? ??? ??? ??? ?? ?????????. 2. ??? ??? ??? ??? ??? ???? ?? ???????. 3. ??? chanstruct {} ??? ?? ?? ? ? ????. ???? ?????? ??? ?, ??? ??? ?? ? ???? ?????.

goensuresmemorysafety? ?? MemolemanucameThrougatomaticgargarbagecollection, nopointerarithmetic, safeconcurrency, andruntimechecks.first, go'sgarbagecollectoricallyally reclaimsunusedmemory, ??, itdisallowspointe, itdisallowspointe ??

GO? ??? ?????? ??????. C? ?? ??? ? ??? ??? ?? ??? ?? ??? ? ??? ???? ?? ?????. 1. ?? ? ???? ?? ???? Go? OS ???? ?? ? ????? ????? ??? ??, ??, ?? ??? ? ???? ?? ?????. OS.ReadFile? ???? ? ?? ??? ?? ??? ?????. ?? ???? ?? ?? ?? ??? ???? ? ?????. 2. ???? ?? ???? OS/EXEC ???? exec.command ??? ?? ??? ????, ??? ????, ?? ??? ????, ?? ? ?? ??? ?????? ?? ??, ??? ?? ? ?? ????? ??? ???? ????? ?? ? ? ????. 3. ???? ? ??? ???? Net ???? TCP/UDP ?????, DNS ?? ? ?? ??? ?????.

GO ???? ?? ??? ????? ?? ???? ????? ?? ? ???? ???? ??? ??? ???? ????????. ?? ???? ??? ?, ???? ? ??? ?? ??? ???? ?? ?? ? ? ????. 1. func (rrectangle) area () int? ?? ? ???? ???? rect.area ()? ?? ?? ??????. 2. ??? ?? ???? ?? func (r*???) setwidth (...)? ?? ??? ???? ???? ???? ?? ??? ???? ?????. 3. ??? ?? ? ?, ?? ??? ??? ?? ? ???, ?? ??? ?? ?? ?? ? ???. 4. Go? Getter/Setter? ??? ???? ??????.

GO?? ?????? ??? ???? ?? ??? ???? ?????. ?????? ??? ???? ???? ??? ??? ???? ?? ??? ?????? ???? ??????. ?? ??, speak () ???? ?? ? ??? ?????? ???? ???? ???? ?? ??? ???? ?? ? ? ????. ?????? ???? ??, ?? ?? ?? ?? ? ????? ?? ????? ???? ? ?????. ?????? ???? ????? ???? ???? ??? ??? ???? ??? ?? ??? ???? ?? ?????? ?????. ???? ?? ???? ??, ??, ?? ?????? ?? ???? ??? ? ?? ???? ?????. ?? ??, ?? ?? ??? ?? ??? ??? ???? ??? Anno? ??? ? ????.

Go Language?? ??? ??? ?? ??? ??? ? ?? ??? ?? ?????. 1.Strings.contains ()? ???? ?? ???? ???? ??? ??? ???? ?? ?? ???? ? ?????. 2.strings.index ()? ???? ?? ???? ???? ??? ?? ? ??? ???? ??? -1? ?????. 3.strings.replaceall ()? ?? ???? ?? ??? ?? ? ? ??? Strings.replace ()? ?? ?? ?? ?? ? ? ????. 4.Len () ??? ???? ??? ??? ?? ? ????? ?? ??? ?? ? ?? ??? ???? ?????? ???????. ??? ??? ?? ??? ???, ??? ?? ?? ? ??? ??? ?? ?????? ?????.

TheGoiopackageprovidesinterfaceslikeReaderandWritertohandleI/Ooperationsuniformlyacrosssources.1.io.Reader'sReadmethodenablesreadingfromvarioussourcessuchasfilesorHTTPresponses.2.io.Writer'sWritemethodfacilitateswritingtodestinationslikestandardoutpu
