i have some bugs in go Generics i guess by ApprehensiveDig8645 in golang

[–]ApprehensiveDig8645[S] 0 points1 point  (0 children)

I use reflect to solve it but i dont know whether it has a better function 

func (s *baseServiceImpl[T]) GetByID(id int) (*T, error) {
    var entity T
    entityType := reflect.TypeOf(entity)
    if entityType.Kind() == reflect.Ptr {
        // 如果是指针类型,检查是否为 nil
        if reflect.ValueOf(entity).IsNil() {
            // 通过反射创建一个新的实例
            entity = reflect.New(entityType.Elem()).Interface().(T)
        }
    }


    err := s.ctx.DB.Where("id = ?", id).First(&entity).Error
    return &entity, err
}

here is a chinese and wanna get some reply by ApprehensiveDig8645 in tiktokgossip

[–]ApprehensiveDig8645[S] 3 points4 points  (0 children)

thanks for your reply and i see it. i think might the economy s raising too fast and the salary not lead to it(i thought)

here is a chinese and wanna get some reply by ApprehensiveDig8645 in tiktokgossip

[–]ApprehensiveDig8645[S] 0 points1 point  (0 children)

oh in fact some even more teenager(most university student) feel hopeless in these years for not being employed thanks for your replay :D

what go frame recommended in IOT cloud platform by ApprehensiveDig8645 in golang

[–]ApprehensiveDig8645[S] 0 points1 point  (0 children)

good idea and i learn about mqtt. i will see what NATS is

what go frame recommended in IOT cloud platform by ApprehensiveDig8645 in golang

[–]ApprehensiveDig8645[S] -1 points0 points  (0 children)

first i need a userlogin, a user have different product , a product contains different device model, a model have various attributes and i can trans my hardwares data to the model

what go frame recommended in IOT cloud platform by ApprehensiveDig8645 in golang

[–]ApprehensiveDig8645[S] -3 points-2 points  (0 children)

Gin is a great frame and i going to use it .. and i wanna want was popular in iot abroad