douyuanliao8815 2016-02-15 12:16
浏览 59
已采纳

简单的申请人名单

I am creating a web application that lists applicants and their position on a waiting list.

We need to be able to add new applicants to this list and remove applicants from the list. There will be under 10k applicants in the list.

Specifics:

  • I plan to write the app in Golang.

  • The list needs to be safe, I the program shuts down, it should be recoverable.

  • The app should contain this data for every applicant: Name, Student ID, position.

Questions:

  1. How do I secure the list (lock?) so it is updated correctly for both if two updates to it is made at the same time?
  2. Should I save the data in a database or use a file?

I need your help!

UPDATE:

Mockup code:

package main

import (
    "log"
    "sync"
    "time"

    "github.com/boltdb/bolt"
)

type applicant struct {
    FirstName string
    LastName  string
    StudentID string
    Position  int
}

type priorityList struct {
    sync.Mutex
    applicants []applicant
}

func (l *priorityList) newApplicant(fn string, ln string, sid string) error {

    // add applicant to priorityList
    return nil
}

func (l *priorityList) removeApplicant(sid string) error {
    // remove applicant from priorityList
    return nil
}

func (l *priorityList) editApplicant(sid string) error {
    // edit applicant in priorityList
    return nil
}

func main() {
    // Database
    db, err := bolt.Open("priorityList.db", 0600, &bolt.Options{Timeout: 1 * time.Second})
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()
}
  • 写回答

2条回答 默认 最新

  • dq804806 2016-02-15 12:21
    关注

    If you use a file, you could use a Mutex to block concurrent writes.

    Otherwise a database would be fine. For example BoltDB could be suitable. It is pure go and runs withing your program.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题